Planetary gravity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
omni123
Posts: 1
Joined: Sat Sep 12, 2009 8:24 am

Planetary gravity

Post by omni123 »

Hi all,

I'm looking at using a Bepu Sphere to represent a planet and obviously the standard method of applying gravity in Bepu isn't of particular use here -- is there a method for applying 3D spherical gravity or should I do it by hand?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Planetary gravity

Post by Norbo »

Technically, you could use the GravitationalField. However, this does some extra computations to determine if objects are within range of the field. Instead, you could create a custom Updateable that applies forces. A simple example is attached.

However, something to keep in mind with large objects is floating point precision. If your planets are actually very large, and especially if they require detailed collision with objects much smaller than themselves, you will most likely encounter some inaccuracies and oddities. There's ways to deal with the issues that arise depending on what you're trying to accomplish.
Attachments
SphereGravity.zip
(919 Bytes) Downloaded 605 times
misscelan
Posts: 3
Joined: Fri Dec 28, 2012 11:40 pm

Re: Planetary gravity

Post by misscelan »

Following up on this thread.

In addition to the planet gravity, is there an easy way to attract some entities and having them always facing upwards?
I want this mainly for characters, so in the event they got attracted they can be standing on their feet.

Many thanks in advance!
Misscelan
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Planetary gravity

Post by Norbo »

It's not too hard to compute an angular velocity or torque to orient an entity- the EntityRotator convenience class could help there. If you don't want full angular control, but instead just 1DOF upright control, you could use logic similar to the internals of the EntityRotator's angular velocity computation, except only work around one axis. The cross product between the current entity up vector and the desired up vector would be useful for this.

Applying that to a CharacterController's body would be trickier, though. The implementation assumes a fixed up axis. It can be modified to use a varying up direction, but that will take some work and fiddling with the CharacterController's different pieces.
misscelan
Posts: 3
Joined: Fri Dec 28, 2012 11:40 pm

Re: Planetary gravity

Post by misscelan »

Thanks for the quick reply!
Post Reply