diff --git a/Assets/Scripts/Player/PlayerAgent.cs b/Assets/Scripts/Player/PlayerAgent.cs index dd9edcd..5006bf9 100644 --- a/Assets/Scripts/Player/PlayerAgent.cs +++ b/Assets/Scripts/Player/PlayerAgent.cs @@ -56,6 +56,7 @@ namespace Projectiles private NetworkMecanimAnimator _netAnim; private static readonly int HashMoveX = Animator.StringToHash("InputX"); // or "MoveX" private static readonly int HashMoveY = Animator.StringToHash("InputY"); // or "MoveY" + [Header("Character Facing")] [SerializeField] private float _turnSpeed = 720f; // deg/sec turning toward desired facing [SerializeField] private bool _faceMoveDirection = true; // if false, faces camera forward (aiming) @@ -93,7 +94,6 @@ namespace Projectiles ProcessMovementInput(); } - // REMOVED: Don't set camera pivot here - it conflicts with LateUpdate // Store the look rotation for LateUpdate to use _lastFUNLookRotation = KCC.GetLookRotation(); } @@ -195,12 +195,17 @@ namespace Projectiles Vector3 inputDir = (camForward * input.MoveDirection.y + camRight * input.MoveDirection.x); inputDir.y = 0f; if (inputDir.sqrMagnitude > 1f) inputDir.Normalize(); + + // Animation blendtree values float moveX = Vector3.Dot(inputDir, camRight); float moveY = Vector3.Dot(inputDir, camForward); const float damp = 0.1f; // seconds to smooth toward target - _anim.SetFloat(HashMoveX, moveX, damp, Time.deltaTime); - _anim.SetFloat(HashMoveY, moveY, damp, Time.deltaTime); + if (_anim != null) + { + _anim.SetFloat(HashMoveX, moveX, damp, Time.deltaTime); + _anim.SetFloat(HashMoveY, moveY, damp, Time.deltaTime); + } // Desired velocity and acceleration/deceleration Vector3 desiredVel = inputDir * _moveSpeed; @@ -213,6 +218,7 @@ namespace Projectiles _moveVelocity = Vector3.Lerp(_moveVelocity, desiredVel, accel * Runner.DeltaTime); // 4) Character facing: toward move dir OR toward camera forward (aim) + // FIXED: Use transform.rotation instead of interfering with KCC look rotation Vector3 faceDir = _faceMoveDirection ? (_moveVelocity.sqrMagnitude > 0.01f ? _moveVelocity : (yawRot * Vector3.forward)) : (yawRot * Vector3.forward); @@ -220,12 +226,9 @@ namespace Projectiles if (faceDir.sqrMagnitude > 0.0001f) { Quaternion target = Quaternion.LookRotation(faceDir, Vector3.up); - // Use KCC for body yaw rotation, but only set the Y (yaw) component - // This keeps the body rotation networked via KCC - Vector2 currentLook = KCC.GetLookRotation(); - float targetYaw = target.eulerAngles.y; - float newYaw = Mathf.MoveTowardsAngle(currentLook.y, targetYaw, _turnSpeed * Runner.DeltaTime); - KCC.SetLookRotation(new Vector2(currentLook.x, newYaw), _minPitch, _maxPitch); + // Use transform rotation for character body - this keeps input and body rotation separate + Quaternion newRot = Quaternion.RotateTowards(transform.rotation, target, _turnSpeed * Runner.DeltaTime); + transform.rotation = newRot; } // 5) Jump