Skip to content

Commit f1444ec

Browse files
committed
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
1 parent 8e7f57a commit f1444ec

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

Source/Actors/Player.cs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,20 +268,27 @@ public override void Update()
268268
{
269269
// Rotate Camera
270270
{
271-
if (!Controls.BackCamera.Pressed)
271+
var rot = new Vec2(cameraTargetForward.X, cameraTargetForward.Y).Angle();
272+
if (Controls.BackCamera.Pressed)
273+
{
274+
rot = Facing.Angle();
275+
}
276+
else if (Controls.Camera.Value.X != 0)
272277
{
273-
var rot = new Vec2(cameraTargetForward.X, cameraTargetForward.Y).Angle();
274278
rot -= Controls.Camera.Value.X * Time.Delta * 4;
275-
276-
var angle = Calc.AngleToVector(rot);
277-
cameraTargetForward = new(angle, 0);
278279
}
279280
else
280281
{
281-
var rot = Facing.Angle();
282-
var angle = Calc.AngleToVector(rot);
283-
cameraTargetForward = new(angle, 0);
282+
// If the camera isn't moving, snap the angle to the nearest 90 degrees if we're close enough
283+
float? cameraPositionToSnapTo = CameraPositionToSnapTo(rot, MathF.PI / 10);
284+
if (cameraPositionToSnapTo.HasValue)
285+
{
286+
rot = Calc.AngleApproach(rot, cameraPositionToSnapTo.Value, 4);
287+
}
284288
}
289+
290+
var angle = Calc.AngleToVector(rot);
291+
cameraTargetForward = new(angle, 0);
285292
}
286293

287294
// Move Camera in / out
@@ -597,6 +604,17 @@ public void GetCameraTarget(out Vec3 cameraLookAt, out Vec3 cameraPosition, out
597604
}
598605
}
599606

607+
private float? CameraPositionToSnapTo(float currentAngle, float sensitivity)
608+
{
609+
for (int i = 0; i < 4; i++)
610+
{
611+
float angle = i * MathF.PI / 2;
612+
if (Calc.AbsAngleDiff(currentAngle, angle) < sensitivity)
613+
return angle;
614+
}
615+
return null;
616+
}
617+
600618
#endregion
601619

602620
#region Various Methods

0 commit comments

Comments
 (0)