- Home /
How round off a vector2?
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.
Answer by Xarbrough · Mar 20, 2018 at 05:18 PM
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.
Your answer
![](https://koobas.hobune.stream/wayback/20220612155006im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how do you make a map which can be circumnavigated? 2 Answers
Double Rounding Problem 1 Answer
vector2 is 0 to 1? 2 Answers
How to get mouse position with ray from camera??? 1 Answer
Cannot implicitly convert type `UnityEngine.Vector2' to `float' 1 Answer