Simultaneous Thrust

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
JanWH
Posts: 11
Joined: Sat Nov 06, 2010 5:48 pm

Simultaneous Thrust

Post by JanWH »

Hello im trying to figure out the engine and bump into an interessting problem.

Applying two impulses at the same frame produces drift.

My Setup:

Code: Select all

phyBody = new Box(Vector3.Zero, 80, 100, 600,10);
phyBody.AngularDamping = 0f;
phyBody.LinearDamping = 0f;
space.Add(phyBody);
Each Frame i do:

Code: Select all

worldPosition = 
 phyBody.InternalCenterOfMass + Vector3.TransformNormal(new Vector3(0, 0, -phyBody.HalfLength), 
 phyBody.InternalOrientationMatrix);
worldDirection = 
 Vector3.TransformNormal(Vector3.Left, phyBody.InternalOrientationMatrix);
phyBody.ApplyImpulse(worldPosition, worldDirection*speedLimit);
worldPosition = 
 phyBody.InternalCenterOfMass + Vector3.TransformNormal(new Vector3(0, 0, phyBody.HalfLength), 
 phyBody.InternalOrientationMatrix);
worldDirection = 
 Vector3.TransformNormal(Vector3.Right, phyBody.InternalOrientationMatrix);
phyBody.ApplyImpulse(worldPosition, worldDirection*speedLimit);
this basicaly simulates a spaceship turning left by fireing two thrusters at oposing sides of the ship one front one at the back.

The effect should be a nice turn on the spot but it drifts off to the side(-x), my theory is that by applaying the first impulse i change the orientation and the second impulse is firing in a different direction and cant counter the first one.

My question is: is there a way to apply them simultaneous?

btw. great work with the engine so far.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Simultaneous Thrust

Post by Norbo »

Those impulses are being applied 'simultaneously' from the perspective of the engine. Unless you put one before a space update and the other after, they take place at the same point in time. You could combine them mathematically so you don't have to call ApplyImpulse twice, but that's more of an optimization- they still occur at the 'same time.' For example, instead of using opposing thrusters, you could just apply an angular impulse (or equivalently, change the angular velocity directly).

Applying an impulse only changes momentum/velocity, not orientation or position. The subsequent space update integrates positions.

However, testing that code produces the expected result. In a zero gravity environment, the box spins without gaining any linear momentum.

By the way, that box is pretty big. I wouldn't recommend using sizes that large if you plan on having stable 'resting' collisions with it or enabling continuous collision detection. The system likes more normal numbers, closer to the 0.5 to 10 units range per entity dimension. It can handle things out of that range well, but staying within that soft range is a good stable rule of thumb.
JanWH
Posts: 11
Joined: Sat Nov 06, 2010 5:48 pm

Re: Simultaneous Thrust

Post by JanWH »

Thanks, i scaled everything down by 10 that did not change much .... but removing the invisible other cube from space that was there from a previous test did the trick.
So its enterly my fault, apologies.
Post Reply