public void UpdateInterpolation() { if (CurrentVehicle != null) { return; } if (GameReference.Exists()) { // interpolate position float Progress = ((float)DateTime.Now.Subtract(Interpolation_Start).TotalMilliseconds) / ((float)Interpolation_End.Subtract(Interpolation_Start).TotalMilliseconds); Vector3 GamePosition = GameReference.Position; GamePosition.Z -= 1.0f; if (GamePosition.DistanceTo(EndPosition) > 5.0f) { GameReference.Position = EndPosition; } // Interpolate velocity Vector3 CurrentVelocity; CurrentVelocity = Vector3.Lerp(StartVelocity, EndVelocity, Progress); GameReference.Velocity = CurrentVelocity; // Interpolate heading float CurrentHeading; Vector2 StartHeading = new Vector2(this.StartHeading, 0); Vector2 EndHeading = new Vector2(this.EndHeading, 0); CurrentHeading = Vector2.Lerp(StartHeading, EndHeading, Progress).X; GameReference.Heading = CurrentHeading; } }
public void UpdateInterpolation() { // Interpolate position if (GameReference.Exists()) { float Progress = ((float)DateTime.Now.Subtract(Interpolation_Start).TotalMilliseconds) / ((float)Interpolation_End.Subtract(Interpolation_Start).TotalMilliseconds); Vector3 GamePosition = GameReference.Position; if (GamePosition.DistanceTo(EndPosition) > 5.0f) { GameReference.Position = EndPosition; } // Interpolate position Vector3 CurrentPosition; CurrentPosition = Vector3.Lerp(StartPosition, EndPosition, Progress); GameReference.Position = CurrentPosition; // Interpolate velocity Vector3 CurrentVelocity; CurrentVelocity = Vector3.Lerp(StartVelocity, EndVelocity, Progress); GameReference.Velocity = CurrentVelocity; // Interpolate Rotation Quaternion CurrentRotation; CurrentRotation = Quaternion.Lerp(StartRotation, EndRotation, Progress); GameReference.RotationQuaternion = CurrentRotation; // Interpolate heading float CurrentHeading; Vector2 StartHeading = new Vector2(this.StartHeading, 0); Vector2 EndHeading = new Vector2(this.EndHeading, 0); CurrentHeading = Vector2.Lerp(StartHeading, EndHeading, Progress).X; GameReference.Heading = CurrentHeading; // Interpolate speed float CurrentSpeed; Vector2 StartSpeed = new Vector2(this.StartSpeed, 0); Vector2 EndSpeed = new Vector2(this.EndSpeed, 0); CurrentSpeed = Vector2.Lerp(StartSpeed, EndSpeed, Progress).X; GameReference.Speed = CurrentSpeed; } }