public override void Update(float deltaTime) { if (IsAutonomWalking) { WalkToward(_walkTowardTarget, _walkTowardThreshold); } base.Update(deltaTime); if (Velocity.X != 0) { Facing = Math.Sign(Velocity.X); } if (CharacterState == CharacterPhysicsState.CPS_PUSHING) { if (Facing != _oldFacing) { CharacterState = CharacterPhysicsState.CPS_IDLE; } } _oldFacing = Facing; if (MotionState == MotionStates.MS_LANDED) { if (Math.Abs(Velocity.X) > 0.001f) { if (CharacterState != CharacterPhysicsState.CPS_PUSHING) { CharacterState = CharacterPhysicsState.CPS_WALKING; } } else { CharacterState = CharacterPhysicsState.CPS_IDLE; } } else if (MotionState == MotionStates.MS_MIDAIR && CharacterState != CharacterPhysicsState.CPS_LANDING && Velocity.Y > 0) { // Get the lower vertices in direction of the jump Vector2 leftVertex = Position + new Vector2(-BoundingBox.XHalfWidth.X, BoundingBox.YHalfWidth.Y); Vector2 rightVertex = Position + new Vector2(BoundingBox.XHalfWidth.X, BoundingBox.YHalfWidth.Y); // Project it to expected position. leftVertex += Velocity * LandingTime + (WorldInfo.Gravity / 2) * LandingTime * LandingTime; rightVertex += Velocity * LandingTime + (WorldInfo.Gravity / 2) * LandingTime * LandingTime; _checkLandingPoints.Add(ConvertUnits.ToDisplayUnits(leftVertex)); _checkLandingPoints.Add(ConvertUnits.ToDisplayUnits(rightVertex)); // Test projected point for collision. Bag <PhysicsObject> leftObjects = WorldInfo.TestPointAll(leftVertex); Bag <PhysicsObject> rightObjects = WorldInfo.TestPointAll(rightVertex); leftObjects.AddAll(rightObjects); for (int i = 0; i < leftObjects.Count; i++) { var curObject = leftObjects[i]; if (curObject == this) { continue; } if (!curObject.IsSensor && curObject.IsActive) { // We got a collision start with landing animation and stop loop CharacterState = CharacterPhysicsState.CPS_LANDING; break; } } } }