diff --git a/Source/Actors/Player.cs b/Source/Actors/Player.cs index cab2b9ae..5abd04db 100644 --- a/Source/Actors/Player.cs +++ b/Source/Actors/Player.cs @@ -269,7 +269,20 @@ public override void Update() // Rotate Camera { var rot = new Vec2(cameraTargetForward.X, cameraTargetForward.Y).Angle(); - rot -= Controls.Camera.Value.X * Time.Delta * 4; + + if (Controls.Camera.Value.X != 0) + { + rot -= Controls.Camera.Value.X * Time.Delta * 4; + } + else + { + // If the camera isn't moving, snap the angle to the nearest 90 degrees if we're close enough + float? cameraPositionToSnapTo = CameraPositionToSnapTo(rot, MathF.PI / 10); + if (cameraPositionToSnapTo.HasValue) + { + rot = Calc.AngleApproach(rot, cameraPositionToSnapTo.Value, 4); + } + } var angle = Calc.AngleToVector(rot); cameraTargetForward = new(angle, 0); @@ -588,6 +601,17 @@ public void GetCameraTarget(out Vec3 cameraLookAt, out Vec3 cameraPosition, out } } + private float? CameraPositionToSnapTo(float currentAngle, float sensitivity) + { + for (int i = 0; i < 4; i++) + { + float angle = i * MathF.PI / 2; + if (Calc.AbsAngleDiff(currentAngle, angle) < sensitivity) + return angle; + } + return null; + } + #endregion #region Various Methods