|
|
@ -1,12 +1,15 @@ |
|
|
|
public partial class CameraController : SpringArm3D |
|
|
|
public partial class CameraController : SpringArm3D |
|
|
|
{ |
|
|
|
{ |
|
|
|
[Export] public Vector2 MouseSensitivity { get; set; } = new(0.2f, 0.2f); // Degrees per pixel. |
|
|
|
|
|
|
|
[Export] public float MovementSmoothing { get; set; } = 8.0f; |
|
|
|
[Export] public float MovementSmoothing { get; set; } = 8.0f; |
|
|
|
[Export] public float PitchMinimum { get; set; } = -85; |
|
|
|
|
|
|
|
[Export] public float PitchMaximum { get; set; } = -25; |
|
|
|
[Export] public Vector2 MouseSensitivity { get; set; } = new(0.2f, 0.2f); // Degrees per pixel. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Export] public float PitchMinimum { get; set; } = 30; |
|
|
|
|
|
|
|
[Export] public float PitchMaximum { get; set; } = 65; |
|
|
|
|
|
|
|
[Export] public float PitchSmoothing { get; set; } = 12.0f; |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: Fix the "snappyness" when moving slowly. |
|
|
|
// FIXME: Fix the "snappyness" when moving slowly. |
|
|
|
// TODO: Add a "soft" minimum / maximum for pitch. |
|
|
|
// FIXME: Fix spring arm clipping through terrain and similar. |
|
|
|
// TODO: Gradually return to maximum spring length. |
|
|
|
// TODO: Gradually return to maximum spring length. |
|
|
|
// TODO: Turn player transparent as the camera moves closer. |
|
|
|
// TODO: Turn player transparent as the camera moves closer. |
|
|
|
|
|
|
|
|
|
|
@ -47,16 +50,20 @@ public partial class CameraController : SpringArm3D |
|
|
|
|
|
|
|
|
|
|
|
void ApplyRotation(Vector2 delta) |
|
|
|
void ApplyRotation(Vector2 delta) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delta *= Tau / 360; // degrees to radians |
|
|
|
var (pitch, yaw, _) = RotationDegrees; |
|
|
|
var (pitch, yaw, _) = Rotation; |
|
|
|
|
|
|
|
yaw += delta.X; |
|
|
|
|
|
|
|
pitch += delta.Y; |
|
|
|
pitch += delta.Y; |
|
|
|
pitch = Clamp(pitch, DegToRad(PitchMinimum), DegToRad(PitchMaximum)); |
|
|
|
yaw += delta.X; |
|
|
|
Rotation = new(pitch, yaw, 0); |
|
|
|
RotationDegrees = new(pitch, yaw, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override void _Process(double delta) |
|
|
|
public override void _Process(double delta) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Position = Position.Damp(_offset + _player.GlobalPosition, MovementSmoothing, delta); |
|
|
|
Position = Position.Damp(_offset + _player.GlobalPosition, MovementSmoothing, delta); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var pitch = RotationDegrees.X; |
|
|
|
|
|
|
|
var (min, max) = (-PitchMaximum, -PitchMinimum); |
|
|
|
|
|
|
|
if (pitch < min) pitch = pitch.Damp(min, PitchSmoothing, delta); |
|
|
|
|
|
|
|
if (pitch > max) pitch = pitch.Damp(max, PitchSmoothing, delta); |
|
|
|
|
|
|
|
RotationDegrees = RotationDegrees with { X = pitch }; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|