# Object is moving the wrong number of units.

I’m trying to make a game based on the Space Shooter tutorial, but with movement similar to Crossy Road.

What is supposed to happen is when the player presses the Left or Right buttons, the ship will slide 10 units in that direction.
I thought I had it pegged down, but I added in code to make the ship rotate as it slid over and I was trying to clean up some messy code and now some funny business is happening. The first time I press a direction after starting the game the ship moves way farther than 10 units in that direction. After that calms down, the ship will move 20 units and on occasion it will go the 10 it is supposed to go.

Am I making a mistake somewhere that I can’t see? Is there a better way I can achieve this movement?
Here is my code and thanks in advance.

``````using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour
{
public float speed = 50;
public float tiltAmt = 30;
public float currentTilt = 0;

private Rigidbody rb;
public Vector3 moveDest = new Vector3(0,0,0);
private float sqrRemainingDistance;

void Start ()
{
rb = GetComponent<Rigidbody> ();
}

void FixedUpdate()
{
sqrRemainingDistance = (rb.transform.position - moveDest).sqrMagnitude;

if (Input.GetKeyDown (KeyCode.LeftArrow)) {
moveDest.x += -10;
rb.rotation = Quaternion.Euler(0f,0f, tiltAmt);
}
if (Input.GetKeyDown (KeyCode.RightArrow)) {
moveDest.x += 10;
rb.rotation = Quaternion.Euler(0f,0f, -tiltAmt);
}

if (sqrRemainingDistance > float.Epsilon)
{
Vector3 newPosition = Vector3.MoveTowards(rb.transform.position, moveDest, Time.deltaTime * speed);

rb.MovePosition (newPosition);

sqrRemainingDistance = (rb.transform.position - moveDest).sqrMagnitude;
}

if(rb.rotation.z != 0)
rb.rotation = Quaternion.RotateTowards(rb.rotation, Quaternion.Euler (0f,0f,0f), Time.deltaTime * (speed * 2));
}

}
``````

`FixedUpdate` can be called multiple times in one frame, depending on the actual frame rate of your scene. According to the documentation of Input.GetKeyDown, it should be called within the `Update()` event, since it is reset at the end of the frame and `Update()` is called only once per frame.