How do I make movement happen over time?

What I’m trying to do is get use the GetKeyDown function to translate an object in X and Z, but I want the transition to happen gradually rather than all at once. For example, if the player presses up, the object’s transform.position.x will increase by 5 over the course of 2 seconds. I basically just want movement to happen visibly over time as it would naturally, rather than popping from one position to another in a single frame. Any help would be appreciated. Thanks!

Use a coroutine like MoveObject.

You can use a variable of velocity for x/z. When you hold down any given key, the velocity increases until it hits a cap. You can use that velocity in conjunction with MoveObject or transform.position assignment to have gradual movement.

You could also look into using a Rigidbody, which is essentially applying real world physics to an object. You can then call functions like ‘AddForce’ when a key is pressed to gradually apply force. This will look more natural, but using a Rigidbody is not always possible depending on what object you need.