using UnityEngine; public class MovingSphere : MonoBehaviour { [SerializeField, Range(0f, 100f)] private float maxSpeed = 10f; [SerializeField, Range(0f, 100f)] private float maxAcceleration = 10f; private Vector3 velocity; private void Update() { Vector2 playerInput; playerInput.x = Input.GetAxis("Horizontal"); playerInput.y = Input.GetAxis("Vertical"); playerInput = Vector2.ClampMagnitude(playerInput, 1f); var desiredVelocity = new Vector3(playerInput.x, 0f, playerInput.y) * maxSpeed; float maxSpeedChange = maxAcceleration * Time.deltaTime; velocity.x = Mathf.MoveTowards(velocity.x, desiredVelocity.x, maxSpeedChange); velocity.z = Mathf.MoveTowards(velocity.z, desiredVelocity.z, maxSpeedChange); var displacement = velocity * Time.deltaTime; transform.localPosition += displacement; } }