# How do I convert a vector into a distance?

I'm doing a 2D raycast where i have to pass distance. The scenario is this:

I'm using rigidbody2d.Moveposition to move my character instantly. However, before a character is moved, i want to do a raycast in that direction. My Movement code is:

if (Input.GetKeyDown (KeyCode.D)) {
rigidbody2D.MovePosition(rigidbody2D.position+speedx);
return;
}


where speedx is Vector2 Vector2(1,0) (can be increased as necessary). So when A is down, first i want to do a raycast to see if it hits any collider and then move or not move the character to that position. However, i'm not able to understand how to set the raycast distance so that it corresponds to the exact distance my character intends to move.

So, what i'm looking for is a way to corelate Vector2 and float.