Help with applying angular impulses and order of operation

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Help with applying angular impulses and order of operation

Post by BrianL »

I've got a craft that I'd like to roll and yaw. It's important that yaw is applied before the roll. However, the best I can do is what appears to be an average application of the forces. The result is that the front corners of the object "dip" when turning. To me, this says that either the roll is being applied first followed by the yaw, or they're both being applied together as an average force. Here's the code; any suggestions on how to correct this or achieve the result I'm looking for:

Code: Select all

PhysicsEntity.applyAngularImpulse( PhysicsEntity.orientationMatrix.Up * Rotation );
PhysicsEntity.applyAngularImpulse( PhysicsEntity.orientationMatrix.Backward * Rotation );
I've noticed that neither the orientationMatrix or the internalOrientationMatrix change after these calls. Maybe that's the problem? Is there another orientation matrix I should be using in order to acquire the immediate results from the preceding call?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Help with applying angular impulses and order of operation

Post by Norbo »

Applying impulses will only immediately change velocities and momentums; if you look at the internalAngularVelocity or internalAngularMomentum they should change. The orientation matrix is updated only when the position is calculated for a new timestep in the update method.

Additionally, the applied impulses just add together. Reversing the order or pre-adding the two impulse vectors in one applyAngularImpulse shouldn't change the result.

If you disable one, do you observe the expected behavior from the other? I think what you might be seeing (assuming these impulses are applied each frame during a turn or some other sustained action) is, as the object rolls sideways, the angular impulse around the local up vector pushes the front corner of the vehicle into the ground. An easy cheat to get around this problem would be using the world up vector (0,1,0) instead of the local, but that has problems of its own if you're looking to have a lot of rotational freedom in your game.
BrianL
Posts: 54
Joined: Wed Jun 25, 2008 4:41 pm
Location: Panama City Beach, FL

Re: Help with applying angular impulses and order of operation

Post by BrianL »

Thanks for the reply. Hopefully that first post didn't come across as implying there was something necessarily wrong. I'm not a physics guru, I leave that up to you guys. So with that being said, yes, I realize that technically the observed behavior is actually correct, depending on the low-level physics implementation.

My next thought for a solution was similar to yours. Use the normal of the underlying surface as the vector to yaw around. I'm pretty confident that should work.
Post Reply