Skip to content

Commit

Permalink
Snap the camera to the nearest 90 degrees if we're close enough
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ZakFahey committed Feb 3, 2024
1 parent e7130d3 commit b005f27
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Source/Actors/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b005f27

Please sign in to comment.