Page 1 of 1

Make gravity force opposite normal

Posted: Fri Sep 07, 2018 8:32 am
by lamxuyen
Hello there. I'm new to Bullet and my goal isn't that standart, that's why i'm here.

Guys, i'm planning to make a game like Spore with generated planet. So there's a question: how do i make gravity force point opposite the direction of the normal in current objects collision?
Thanks for your patience. :wink:

Re: Make gravity force opposite normal

Posted: Fri Sep 07, 2018 3:32 pm
by drleviathan
Do you mean: "How to implement a planet's gravitational field in Bullet?" ?

If so, here is some info:

Bullet has a World gravity setting (btDiscreteDynamicsWorld::setGravity()) but it is uniform.

You can override the World gravity on a per-object basis: btRigidBody::setGravity().

For a radial gravity field you would need update the gravity of each dynamic body every frame. This could be done in a few ways but the one that makes the most sense would be: derive a custom class called MyDynamicsWorld from btDiscreteDynamicsWorld and override btDiscreteDynamicsWorld::applyGravity() to do your bidding.

If you really want to set an object's gravity based on the normal of an instantaneous collision (which sounds like a Bad Idea to me) then perhaps you could elaborate on what you really want to do.