From a9f51b62c04897527e6cacaf86c4da6d3b540bde Mon Sep 17 00:00:00 2001 From: Chris Date: Sun, 10 Aug 2025 12:24:41 -0400 Subject: [PATCH] fixed: all moving conditions working. removed 'moveFacing' primarily --- Assets/Scripts/Player/UnitMovementHandler.cs | 63 +++++++------------- 1 file changed, 21 insertions(+), 42 deletions(-) diff --git a/Assets/Scripts/Player/UnitMovementHandler.cs b/Assets/Scripts/Player/UnitMovementHandler.cs index 42a6a85..10e7976 100644 --- a/Assets/Scripts/Player/UnitMovementHandler.cs +++ b/Assets/Scripts/Player/UnitMovementHandler.cs @@ -9,7 +9,8 @@ public enum PlayerFacingDirection{ TowardsTarget = 0, MatchForward, MatchCamera, - Static + Static, + Momentum } namespace Reset.Units{ @@ -19,9 +20,6 @@ namespace Reset.Units{ // } public class UnitMovementData{ // Movement Direction - public Vector3 targetMoveDirection; - public PlayerFacingDirection moveFacing; - public float accelerationSmoothing = 5f; public float deaccelerationSmoothing = 5f; public AnimationCurve deaccelerationCurve; @@ -77,15 +75,11 @@ namespace Reset.Units{ UpdateCurrentSpeed(); UpdateCurrentGravity(); UpdateCurrentRotation(); - // + DoMovement(); } private void UpdateCurrentDirection(){ - // Construct move direction - Vector3 targetDirection = data.targetMoveDirection; - - Debug.Log(controls); // Get input value Vector3 inputMovement = new Vector3( @@ -94,27 +88,12 @@ namespace Reset.Units{ 0f, controls. rawMoveInput.y); - + + // Construct move direction + Vector3 targetDirection = inputMovement; + if (inputMovement.magnitude < .1f) { - inputMovement = Vector3.zero; - } - - // Change how movement is managed based on facing state - switch (data.moveFacing) { - case PlayerFacingDirection.TowardsTarget: - break; - case PlayerFacingDirection.MatchForward: // TODO: Recomment - // targetDirection = agent.transform.forward * inputMovement.magnitude; - targetDirection = inputMovement; - break; - case PlayerFacingDirection.MatchCamera: - targetDirection = Quaternion.Euler(Camera.main.transform.forward.DirectionTo(transform.forward)) * inputMovement; // NOTE: This used to be t: currentRotSpeed * Time.deltaTime. - // See how it feels with a hard set value and go fro there. - break; - case PlayerFacingDirection.Static: - break; - default: - throw new ArgumentOutOfRangeException(); + targetDirection = Vector3.zero; } // Remove Y from variables @@ -123,7 +102,7 @@ namespace Reset.Units{ // Smooth movement if (targetNoY.magnitude > currentNoY.magnitude) { - currentNoY = Vector3.Lerp(currentNoY, targetNoY,data.accelerationSmoothing * Time.deltaTime); + currentNoY = Vector3.Slerp(currentNoY, targetNoY,data.accelerationSmoothing * Time.deltaTime); } else { float deaccelValue = data.deaccelerationCurve.Evaluate(inputMovement.magnitude); @@ -164,28 +143,28 @@ namespace Reset.Units{ Vector3 inputMovement = new Vector3(controls.rawMoveInput.x, 0f, controls.rawMoveInput.y); switch (data.rotateFacing) { + // TODO: Recomment case PlayerFacingDirection.TowardsTarget: - // Set rotation to just the direction of the target - Debug.LogError("Not implemented..."); - + break; + case PlayerFacingDirection.Momentum: + if (inputMovement.magnitude > .03f){ + outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(outputMoveDirection); + } break; case PlayerFacingDirection.MatchForward: if (controls.rawMoveInput.magnitude < 0.01f) { break; } - - outputRotation = Quaternion.LookRotation(inputMovement) * - Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0f, null, 0f)); - + outputRotation = Camera.main.transform.rotation * Quaternion.LookRotation(inputMovement); + break; case PlayerFacingDirection.MatchCamera: - // Craft a new rotation that flattens the camera's rotation to the ground - // Needed to keep the character from inheriting the camera's height-rotation - outputRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0)); + + outputRotation = Quaternion.Euler(Camera.main.transform.rotation.eulerAngles.Flatten(0, null, 0)); break; case PlayerFacingDirection.Static: outputRotation = transform.rotation; break; - } + } // Set final rotation transform.rotation = Quaternion.Lerp(transform.rotation, outputRotation, 10f * Time.deltaTime).Flatten(0, null, 0); @@ -196,7 +175,7 @@ namespace Reset.Units{ } public void DoMovement(Vector3 moveDir, float speed){ - Debug.Log( outputMoveDirection);; + // Commit the move, with respect to the camera's rotation controller.Move((Camera.main.transform.rotation.Flatten(0, null, 0) * (moveDir * speed) * Time.deltaTime)); }