Relative Gravity with Planets

Alright,

First off, apologies if this was already mentioned or brought forth. However, I scoured the net and still could not find a solid answer.
Me and a friend of mine are working on a space simulator game and we need relative gravity to the planets, suns, etc etc, but I have no idea where to even start. Currently we have a regular setGravity with a CharacterControl and everything (as in planet and the sun) is set with static RigidBodyControl. I’ve heard about using forces and stuff but I’m a bit of a noob in the advanced physics world.

Here’s a lil sneak preview

Thanks much

This is the right one xD

Look at this post http://hub.jmonkeyengine.org/forum/topic/bettercharactercontrol-in-the-works/
maybe it can help

If we are talking about ‘real’ space simulator with serious distances between planets, forget about using bullet physics for simulating gravity. It is designed for completely different things.

No, having gravity in first place… Why do you want to have it in space sim? You will anyway need some kind of ‘warp’ drive to move around solar system. Gravity counts only if you are flying for days/weeks - so unless you go for really really boring space sim, you should ignore system-wide gravity interactions and care only about immediate vicinity of planets. But even that is way too big to be fun in simulation.

Maybe you can tell what kind of effect you want to achieve - because simulating solar system with real gravity for sure is not that…

If you want to look into ‘realistic’ space sim, please take a look at Orbiter + some plugins. It is really, really, really boring thing…

<cite>@abies said:</cite> If we are talking about 'real' space simulator with serious distances between planets, forget about using bullet physics for simulating gravity. It is designed for completely different things.

I think I failed to mention that we’re scoping along the lines with a game called Shores of Hazeron. Haha my bad. I think my true problem is is being able to walk around the cube planet. So, for a new approach, how could I achieve something like Angry Birds Space with JBullet?

set the gravity per object manually via setGravity, update it if moved more then x meters, to respect the new one.

(And please for the love of god, build in clientside interpolation or I might to kill you^^)

I have relative gravity between very large distances (earth to the moon) in the jmeplanet SpaceMonkey demo. Bullet physics work fine.

jmeplanet

<cite>@aaronperkins said:</cite> I have relative gravity between very large distances (earth to the moon) in the jmeplanet SpaceMonkey demo. Bullet physics work fine.

jmeplanet

At least in the demo, it is not a very large distance - it is very, very short distance.
Additionally, if the gravity would work properly, these two bodies would collide with each other very soon.

REAL gravity simulation would mean that object put into space somewhere between the bodies wit some speed would deorbit and hit the ‘earth’ after 2 months for example. I challenge anybody to program it in bullet in this way you won’t hit floating point errors over 2 months of miniscule incremental gravity effects.

But as echospot remarked, it is not really about ‘space simulation’ but just a game - in such case everything which works, works.

There’s this , which states that the gravity depends on the squared distance - it’s up to you to tweak G, m1 and m2 so that it fits your game.
If you want to enter the atmosphere, another fun thing to take into account is air friction, which will slow your objects down. The interesting thing about it is that it depends on your objects size and form (“reference area”), as well as the density of the air, which changes the closer you get to earth. The formula for the air friction is . And the density of the air at different height’s is given by , where you have to insert the formula for the air pressure , which is changing with the height, and the formula for the temperature , which is also changing with the height. Once again, you can tweak these values, but it’s a good starting point if you want to create an interesting simulation, because now you know that distance and friction play a role, which then again depend on area, air density, air pressure, temperature and height. And most importantly, friction gets bigger by velocity squared.
You can simply add up all gravity forces of the different planets each frame, beforce applying the final force to your object.

2 Likes

Thanks all for the help.

So yea, after the point brought up by @abies ,

<cite>@abies said:</cite> If we are talking about 'real' space simulator with serious distances between planets, forget about using bullet physics for simulating gravity. It is designed for completely different things.

No, having gravity in first place… Why do you want to have it in space sim? You will anyway need some kind of ‘warp’ drive to move around solar system…

I will adopt the simpler gravity method (As much as I like to enjoy watching CPU’s melt while playing my game :-D) that @EmpirePhoenix explained.

<cite>@Empire Phoenix said:</cite> set the gravity per object manually via setGravity, update it if moved more then x meters, to respect the new one.

(And please for the love of god, build in clientside interpolation or I might to kill you^^)

As for entering the atmosphere and air friction, as explained by @cvlad,

<cite>@cvlad said:</cite> If you want to enter the atmosphere, another fun thing to take into account is air friction, which will slow your objects down. The interesting thing about it is that it depends on your objects size and form ("reference area"), as well as the density of the air, which changes the closer you get to earth. The formula for the air friction is . And the density of the air at different height's is given by , where you have to insert the formula for the air pressure , which is changing with the height, and the formula for the temperature , which is also changing with the height. Once again, you can tweak these values, but it's a good starting point if you want to create an interesting simulation, because now you know that distance and friction play a role, which then again depend on area, air density, air pressure, temperature and height. And most importantly, friction gets bigger by velocity squared. You can simply add up all gravity forces of the different planets each frame, beforce applying the final force to your object.

This will be good for metering ships on reentry to see if the player’s burn up or not. Thanks all for the help! Hope this all works haha