I’ve written a script to move the camera based on keyboard input, which I pieced together from several parts of the Roll a Ball tutorial. However, when I release the key, it takes a fraction of a second for the movement to stop. Obviously, that’s not optimal.
void Update ()
{
float horizontal = Input.GetAxis ("Pan Horizontal");
float vertical = Input.GetAxis ("Pan Vertical");
float zoom = Input.GetAxis ("Zoom");
Vector3 position = transform.position;
if (horizontal < 0) position.x += .1f;
if (horizontal > 0) position.x -= .1f;
if (vertical < 0) position.z += .1f;
if (vertical > 0) position.z -= .1f;
if (zoom < 0) position.y += .5f;
if (zoom > 0) position.y -= .5f;
transform.position = position;
}
Looking online, it seems there are MANY different ways to do this, but most of the examples I’ve seen have Time.deltaTime somewhere in the math. I thought adding this would fix the problem, but it only seems to have slowed down the movement rather than fix the input.
if (horizontal < 0) position.x += 10f * Time.deltaTime;
I could easily copy/paste someone else’s script, but I’d prefer to understand what’s wrong with my script and what parts need to change, rather than simply shove something in without educating myself.