PDA

View Full Version : Black Hole - Sucking physics


Jesse Aldridge
03-29-2007, 10:53 AM
Hey folks. I'm trying to model a black hole in 2d, but I have a problem. First let me say that I'm not doing any realistic physics modeling here, I just want a thing that draws a spaceship toward it, and if the ship gets too close it won't be able to escape because the force will be too great.

So, I apply a force to the spaceship to make it move toward the black hole, and that works fine. But by the time the ship reaches the center of the hole it's built up so much velocity that it flies past the hole, rather then getting trapped in the middle like I want. I guess I could just clear the ship's velocity if it's within x distance of the hole, but that seems pretty inelegant. Could someone help me out here?

luggage
03-29-2007, 11:05 AM
Try making the force you apply to the ship greater the closer to the center of the black hole. Then ensure that the maximum force you apply is greater than your ships maximum velocity. That might work.

Hamumu
03-29-2007, 11:06 AM
In real life, gravity decreases as the square of the distance. That's what you need - it needs to suck exponentially more the closer you get (want to insert joke about bad painter here, but don't know one). If the value is sufficiently high, then when you get in really close, the pull inward will greatly outweigh the existing momentum.

Matthew
03-29-2007, 11:09 AM
The key is max velocity of the ship. If you don't have a max velocity, it'll gain just as much speed from moving towards the hole as it it'll lose moving away (so if you have some starting velocity from the player it'll never get stuck).

That, or just manually kill velocity on the ship when it's inside the radius of the black hole...

Matthew
03-29-2007, 11:22 AM
Actually, you could try this too:

- Establish a radius around the black hole for this additional effect
- If you're 70% of the way in, reduce the ship's velocity by 70% and redirect lost speed towards the black hole:

vShipVelocity += vBrakingForce * speed * 0.7
vShipVelocity += vDirectionTowardsHole * speed * 0.7

vBrakingForce and vDirectionTowardsHole are unit vectors describing the opposite velocity of the ship and the direction towards the black hole.

This should prevent orbits and the like while maintaining the ship's speed, IIRC.

Jesse Aldridge
03-29-2007, 12:18 PM
Ok, I think my main problem was that I didn't have a max velocity for the ship. I added a drag function like so:

drag = -.000001f * velocity.lengthSquared()
velocity += velocity * drag

And things seem to be working. Thanks for the help guys!

Pyabo
03-29-2007, 12:32 PM
But by the time the ship reaches the center of the hole it's built up so much velocity that it flies past the hole, rather then getting trapped in the middle like I want.

Isn't that what's supposed to happen? It's called an "orbit." :)

F = G * m1*m2 / d^2

Huge
03-29-2007, 09:37 PM
Isn't that what's supposed to happen? It's called an "orbit." :)

F = G * m1*m2 / d^2

Yes you are right! However, for back holes, there is no longer an inverse square law, and there is no stable orbit beyond a certain point (your orbit length is no longer pi*D). I think limiting the velocity is the key - after all this is somewhat like what happens - you don't go faster than the speed of light. One thing might look cool if you have a "speedometer" is to have it in terms of the speed of light. So rather than hard-limiting it a "1", have it aproach like: 99%, 99.9%, 99.99% etc.

Pelican
03-30-2007, 05:40 AM
One thing worth noting on this subject - because the acceleration is variable, you might have to be careful with regard to your time-step. If you just want a basic sort of effect, you won't need to worry about "proper" integration (ie you can just recalculate the effect on your velocity every frame as described), but it is definitely worth having a fixed timestep in this sort of code. Otherwise the behaviour can vary quite a lot, which may not be what you want.

You may be doing this anyway, in which case ignore me :)

Artinum
03-31-2007, 05:00 AM
The famous thing about black holes is that the laws of physics break down rather dramatically beyond the event horizon. No wonder you're having trouble! To an extent it is (and should be) possible to slingshot round the black hole and not be pulled in - I do not recommend trying this at home, folks.

Ordinarily with gravity stuff we cheat and use basic particle physics - that is, the spaceship is considered as a single particle. Everything balances out and your planetary orbits, etc, all work fine. Black holes are rather weirder, certainly so when you get very close to them.

Ever heard of spaghettification? This is the theory that anything pulled into a black hole is stretched out into a long, thin string, because the gravity at the "feet" is much stronger than the gravity at the "head". That inverse square law gets extreme near the centre of a singularity. The same effect occurs near any gravity source, even on Earth, but the difference is so minor here we would never notice it.

I know this doesn't really answer your question but the actual physical effect when you got too close to the black hole would be the destruction of the ship, not merely getting stuck. A neat visual effect of the ship being stretched into spaghetti and spiralling into the singularity would be cool.