From b005f270cf8934f9bb0a8785db3843a202b2b447 Mon Sep 17 00:00:00 2001 From: ZakFahey Date: Sat, 3 Feb 2024 09:41:37 -0800 Subject: [PATCH] Snap the camera to the nearest 90 degrees if we're close enough While playing the game I was bothered by the fact that the camera can get misaligned to where it's just a few degrees shy of straight forward. This makes it annoying to line up some jumps. So now, when you get within 18 degrees of one of the four 90 degree directions, you'll snap straight ahead. I played around with the numbers, and this amount of sensitivity feels best. If you think the number should be lower or higher, let me know. Here is a demonstration of the change: https://www.youtube.com/watch?v=sUO0gDmANLQ --- Source/Actors/Player.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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