diff --git a/Assets/Scripts/Player/PlayerAvatar.cs b/Assets/Scripts/Player/PlayerAvatar.cs index d8cf657..6c9eaaf 100644 --- a/Assets/Scripts/Player/PlayerAvatar.cs +++ b/Assets/Scripts/Player/PlayerAvatar.cs @@ -33,6 +33,12 @@ namespace Jankenbots.Prototype [Tooltip("Run speed in m/s.")] public float moveSpeed = 5f; + [Tooltip("How fast the avatar ramps UP to full speed (m/s^2). Lower = floatier start.")] + public float acceleration = 45f; + + [Tooltip("How fast the avatar ramps DOWN to a stop (m/s^2). Higher = snappier stop.")] + public float deceleration = 60f; + [Tooltip("How fast the avatar turns to face its movement direction (deg/s).")] public float turnSpeed = 720f; @@ -46,6 +52,7 @@ namespace Jankenbots.Prototype CharacterController _cc; Animator _anim; float _vy; // vertical velocity (gravity) + Vector3 _horizVel; // smoothed horizontal velocity (ramped, not instant) Vector3 _lastPos; float _animSpeed; static readonly int SpeedHash = Animator.StringToHash("Speed"); @@ -98,16 +105,23 @@ namespace Jankenbots.Prototype Vector3 input = new Vector3(h, 0f, v); if (input.sqrMagnitude > 1f) input.Normalize(); - Vector3 move = input * moveSpeed; + Vector3 desired = input * moveSpeed; + + // Ramp velocity toward the target instead of snapping — this is what kills + // the "jerky/jarring" feel and lets the anim blend Idle→Walk→Run smoothly. + float rate = input.sqrMagnitude > 0.001f ? acceleration : deceleration; + _horizVel = Vector3.MoveTowards(_horizVel, desired, rate * Time.deltaTime); if (_cc.isGrounded && _vy < 0f) _vy = -2f; _vy += gravity * Time.deltaTime; - _cc.Move((move + new Vector3(0f, _vy, 0f)) * Time.deltaTime); + _cc.Move((_horizVel + new Vector3(0f, _vy, 0f)) * Time.deltaTime); - if (move.sqrMagnitude > 0.01f) + // Face the way we're actually moving (uses the smoothed velocity, so turns + // ease too rather than snapping on a key change). + if (_horizVel.sqrMagnitude > 0.05f) { - Quaternion target = Quaternion.LookRotation(new Vector3(move.x, 0f, move.z)); + Quaternion target = Quaternion.LookRotation(new Vector3(_horizVel.x, 0f, _horizVel.z)); transform.rotation = Quaternion.RotateTowards(transform.rotation, target, turnSpeed * Time.deltaTime); } }