Hello. How i can round coordinates of vector without leave direction (make all vectors with same length)?
I want to make a vectors of the same length.
Thank you.
Hello. How i can round coordinates of vector without leave direction (make all vectors with same length)?
I want to make a vectors of the same length.
Thank you.
Like this:
Vector2 myVector = new Vector2(13f, 7f);
Vector2 direction = myVector.normalized;
float desiredLength = 1f;
Vector2 newVector = direction * desiredLength;
First you only take the normalized direction (has a length of 1), then you scale the magnitude of that vector by the length you want (multiply the direction with length 1 by the length value). I wouldn’t call this “rounding”, but “scaling” instead. There’s also a similar method called Vector3.ClampMagnitude, which clamps the length of a vector to a max value, but allows smaller ones, so not exactly what you wanted, but also helpful.