diff --git a/Scripts/Misc/CameraController3D.cs b/Scripts/Misc/CameraController3D.cs index 4e3c2ba2..eab1b523 100644 --- a/Scripts/Misc/CameraController3D.cs +++ b/Scripts/Misc/CameraController3D.cs @@ -8,9 +8,6 @@ public partial class CameraController3D : Camera3D [Export] public bool EnableSmoothing = 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); @@ -96,90 +93,45 @@ public partial class CameraController3D : Camera3D { _currentPosition = desiredCameraPos; } - - // if (CameraSnapStep > 0f) - // { - // _currentPosition = Snap(_currentPosition, CameraSnapStep); - // } + + GlobalPosition = _currentPosition; - if (SnapCamera) - { - GlobalPosition = SnapToPixelGrid(_currentPosition); - } - else - { - GlobalPosition = _currentPosition; - } //GlobalPosition = _currentPosition; // No LookAt or dynamic rotation — angle is fixed } private Vector3 GetAimOffsetWorldSpace() { - Vector2 stickDir = new Vector2( + var stickDir = new Vector2( Input.GetActionStrength(AimRightName) - Input.GetActionStrength(AimLeftName), Input.GetActionStrength(AimDownName) - Input.GetActionStrength(AimUpName) ); - float stickLen = stickDir.Length(); + var stickLen = stickDir.Length(); if (stickLen > AimDeadzone) { - float scaled = (stickLen - AimDeadzone) / (1f - AimDeadzone); - Vector2 aimDir2D = stickDir.Normalized() * Mathf.Clamp(scaled, 0f, 1f); + var scaled = (stickLen - AimDeadzone) / (1f - AimDeadzone); + var aimDir2D = stickDir.Normalized() * Mathf.Clamp(scaled, 0f, 1f); return new Vector3(aimDir2D.X, 0, aimDir2D.Y); } // Mouse fallback - Vector2 mousePos = GetViewport().GetMousePosition(); - Vector3 rayOrigin = ProjectRayOrigin(mousePos); - Vector3 rayDir = ProjectRayNormal(mousePos) * 1000f; + var mousePos = GetViewport().GetMousePosition(); + var rayOrigin = ProjectRayOrigin(mousePos); + var rayDir = ProjectRayNormal(mousePos) * 1000f; var plane = new Plane(Vector3.Up, 0); var hit = plane.IntersectsRay(rayOrigin, rayDir); - if (hit is Vector3 hitPoint) + if (hit is not { } hitPoint) return Vector3.Zero; { - Vector3 offset = hitPoint - _target.GlobalTransform.Origin; + var offset = hitPoint - _target.GlobalTransform.Origin; offset.Y = 0; - float dist = offset.Length(); - if (dist > 0.01f) - { - float scaled = Mathf.Clamp((dist - AimDeadzone) / (10f - AimDeadzone), 0f, 1f); - return offset.Normalized() * scaled; - } + var dist = offset.Length(); + if (!(dist > 0.01f)) return Vector3.Zero; + var scaled = Mathf.Clamp((dist - AimDeadzone) / (10f - AimDeadzone), 0f, 1f); + return offset.Normalized() * scaled; } - - 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) - // ); - // } - } \ No newline at end of file