public override void Iterate() { deltaVelocity = TargetVelocity - Body1.LinearVelocity; deltaVelocity.Y = 0.0f; // determine how 'stiff' the character follows the target velocity deltaVelocity *= this.Stiffness; if (deltaVelocity.LengthSquared() != 0.0f) { // activate it, in case it fall asleep :) Body1.IsActive = true; Body1.ApplyImpulse(deltaVelocity * Body1.Mass); } if (shouldIJump) { Body1.IsActive = true; Body1.ApplyImpulse(JumpVelocity * JVector.Up * Body1.Mass); if (!BodyWalkingOn.IsStatic) { BodyWalkingOn.IsActive = true; // apply the negative impulse to the other body BodyWalkingOn.ApplyImpulse(-1.0f * JumpVelocity * JVector.Up * Body1.Mass); } } }
public override void Iterate() { _deltaVelocity = TargetVelocity - Body1.LinearVelocity; _deltaVelocity.Y = 0.0f; _deltaVelocity *= Stiffness; if (Math.Abs(_deltaVelocity.LengthSquared()) > 0.00001f) { Body1.IsActive = true; Body1.ApplyImpulse(_deltaVelocity * Body1.Mass); } if (_shouldIJump) { Body1.IsActive = true; Body1.ApplyImpulse(JumpVelocity * JVector.Up * Body1.Mass); if (!BodyWalkingOn.IsStatic) { BodyWalkingOn.IsActive = true; BodyWalkingOn.ApplyImpulse(-1.0f * JumpVelocity * JVector.Up * Body1.Mass); } } }