How can I add distance moved into this code?

Hello, I’m sort of new with player movement. I can’t seem to try and make my player move at specific distance. Instead of (1,1,1) each time i hit arrow key, i want it lower, like (0.2,0.2,0.2). Any sort of help is appreciated !

.

``````private float speed = 2.0f;
private Vector3 pos;

void Start()
{
pos = transform.position;

}

void Update()
{

if (Input.GetKeyDown(KeyCode.RightArrow) && transform.position == pos)
{
pos += Vector3.right;
}
else if (Input.GetKeyDown(KeyCode.LeftArrow) && transform.position == pos)
{
pos += Vector3.left;
}
else if (Input.GetKeyDown(KeyCode.UpArrow) && transform.position == pos)
{
pos += Vector3.up;
}
else if (Input.GetKeyDown(KeyCode.DownArrow) && transform.position == pos)
{
pos += Vector3.down;
}

transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
}
``````

}

Vector3.right and Vector3.left are just short ways of writing (1, 0, 0) or (-1, 0, 0). So if you wanted to make your player move at a smaller distance, you would multiply Vector3.right by your speed. Making your speed like 0.2f, would cause your player to move 0.2 units to the right whenever you press the right arrow key. Finally, theres a better way of writing your current code. You could write instead:

``````        float speed = 20f;

void Update()
{
float x = Input.GetAxis("Horizontal"); //Left and right arrow keys
float y = Input.GetAxis("Vertical"); //Up and down arrow keys

Vector3 pos = Vector3.right * x + Vector3.up * y;

transform.position = Vector3.MoveTowards(transform.position, pos, Time.deltaTime * speed);
}
``````

@sNo73