public void Update(ComponentizedEntity entity, IGameContext gameContext, IUpdateContext updateContext) { if (!Enabled) { return; } if (_jitterWorld != _physicsEngine.GetInternalPhysicsWorld()) { // TODO: Deregister rigid bodies from old world. if (_jitterWorld != null && _physicsControllerConstraint != null) { _jitterWorld.RemoveConstraint(_physicsControllerConstraint); _physicsControllerConstraint = null; } _jitterWorld = _physicsEngine.GetInternalPhysicsWorld(); } if (_physicalComponent.RigidBodies.Length > 0 && _physicalComponent.RigidBodies[0] != _rigidBody) { if (_physicsControllerConstraint != null) { _jitterWorld.RemoveConstraint(_physicsControllerConstraint); _physicsControllerConstraint = null; } } if (_physicalComponent.RigidBodies.Length > 0) { if (_physicsControllerConstraint == null) { _physicsControllerConstraint = new PhysicsControllerConstraint( _jitterWorld, _physicalComponent.RigidBodies[0]); _jitterWorld.AddConstraint(_physicsControllerConstraint); } _physicsControllerConstraint.TargetVelocity = TargetVelocity.ToJitterVector(); _physicsControllerConstraint.TryJump = TryJump; _physicsControllerConstraint.JumpVelocity = JumpVelocity; _physicsControllerConstraint.Stiffness = Stiffness; if (TargetVelocity.LengthSquared() > 0f) { // Wake up the rigid body. _physicalComponent.RigidBodies[0].IsActive = true; } } }
public void Update(ComponentizedEntity entity, IGameContext gameContext, IUpdateContext updateContext) { if (!Enabled) { return; } if (_jitterWorld != _physicsEngine.GetInternalPhysicsWorld()) { // TODO: Deregister rigid bodies from old world. if (_jitterWorld != null && _physicsControllerConstraint != null) { _jitterWorld.RemoveConstraint(_physicsControllerConstraint); _physicsControllerConstraint = null; } _jitterWorld = _physicsEngine.GetInternalPhysicsWorld(); } if (_physicalComponent.RigidBodies.Length > 0 && _physicalComponent.RigidBodies[0] != _rigidBody) { if (_physicsControllerConstraint != null) { _jitterWorld.RemoveConstraint(_physicsControllerConstraint); _physicsControllerConstraint = null; } } if (_physicalComponent.RigidBodies.Length > 0) { if (_physicsControllerConstraint == null) { _physicsControllerConstraint = new PhysicsControllerConstraint( _jitterWorld, _physicalComponent.RigidBodies[0]); _jitterWorld.AddConstraint(_physicsControllerConstraint); } _physicsControllerConstraint.TargetVelocity = TargetVelocity.ToJitterVector(); _physicsControllerConstraint.TryJump = TryJump; _physicsControllerConstraint.JumpVelocity = JumpVelocity; _physicsControllerConstraint.Stiffness = Stiffness; if (TargetVelocity.LengthSquared() > 0f) { // Wake up the rigid body. _physicalComponent.RigidBodies[0].IsActive = true; } } }