mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-02 14:31:16 +00:00
Camera Jitter fix
This commit is contained in:
parent
133f4088d0
commit
4eea1f7389
1 changed files with 48 additions and 2 deletions
|
|
@ -8,6 +8,9 @@ public partial class CameraController3D : Camera3D
|
||||||
|
|
||||||
[Export] public bool EnableSmoothing = true;
|
[Export] public bool EnableSmoothing = true;
|
||||||
[Export] public bool FollowTargeting = true;
|
[Export] public bool FollowTargeting = true;
|
||||||
|
[Export] public bool SnapCamera = true;
|
||||||
|
|
||||||
|
// [Export] public float CameraSnapStep = 0.02f; // 0 = disabled
|
||||||
|
|
||||||
[Export] public Vector3 DefaultCameraRotation = new Vector3(-36f, 45f, 0f);
|
[Export] public Vector3 DefaultCameraRotation = new Vector3(-36f, 45f, 0f);
|
||||||
|
|
||||||
|
|
@ -59,7 +62,7 @@ public partial class CameraController3D : Camera3D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
if (_target is null) return;
|
if (_target is null) return;
|
||||||
|
|
||||||
|
|
@ -94,7 +97,20 @@ public partial class CameraController3D : Camera3D
|
||||||
_currentPosition = desiredCameraPos;
|
_currentPosition = desiredCameraPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalPosition = _currentPosition;
|
// if (CameraSnapStep > 0f)
|
||||||
|
// {
|
||||||
|
// _currentPosition = Snap(_currentPosition, CameraSnapStep);
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (SnapCamera)
|
||||||
|
{
|
||||||
|
GlobalPosition = SnapToPixelGrid(_currentPosition);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GlobalPosition = _currentPosition;
|
||||||
|
}
|
||||||
|
//GlobalPosition = _currentPosition;
|
||||||
// No LookAt or dynamic rotation — angle is fixed
|
// No LookAt or dynamic rotation — angle is fixed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,4 +152,34 @@ public partial class CameraController3D : Camera3D
|
||||||
|
|
||||||
return Vector3.Zero;
|
return Vector3.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Vector3 SnapToPixelGrid(Vector3 worldPos)
|
||||||
|
{
|
||||||
|
var viewport = GetViewport();
|
||||||
|
float viewportHeight = viewport.GetVisibleRect().Size.Y;
|
||||||
|
|
||||||
|
// World units per screen pixel
|
||||||
|
float unitsPerPixel = (Size * 2f) / viewportHeight;
|
||||||
|
|
||||||
|
return new Vector3(
|
||||||
|
Mathf.Round(worldPos.X / unitsPerPixel) * unitsPerPixel,
|
||||||
|
Mathf.Round(worldPos.Y / unitsPerPixel) * unitsPerPixel,
|
||||||
|
Mathf.Round(worldPos.Z / unitsPerPixel) * unitsPerPixel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// private static float Snap(float value, float step)
|
||||||
|
// {
|
||||||
|
// return Mathf.Round(value / step) * step;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private static Vector3 Snap(Vector3 v, float step)
|
||||||
|
// {
|
||||||
|
// return new Vector3(
|
||||||
|
// Snap(v.X, step),
|
||||||
|
// Snap(v.Y, step),
|
||||||
|
// Snap(v.Z, step)
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue