- Home /
Vector3 normalize gives wierd results
i just wanted to normalize a vector but it gives wierd results.wasted several hours :-(
void Update()
{
Vector3 i = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 b= transform.position;
Vector3 n = i-b;
n.Normalize();
Debug.DrawLine(b, i, Color.green);
Debug.DrawLine(b,n , Color.blue);
}
i have set the z cordinates to zero that doesnt help either.
Answer by revolute · Oct 31, 2019 at 05:31 AM
DrawLine accepts values from - to. Normalized vector would be (0.9,0.4) (random guess from your image) and the image shows the right result.
"to" is the point where the line will end. Essentially you are drawing a line to (0.9,0.4) not extending in the direction. You are putting a directional vector whereas the method expects a point.
No.even if i multiply the direction with a value.it shows the same result.keeping magnitude apart the directions for both lines should be the same.but they arent.
Try this:
n.z = 0;
n.Normalize();
Debug.DrawLine(b,b+n*(i-b).magnitude, Color.blue);
$$anonymous$$y statement holds true. You are mixing up points and vectors.
Thanks yeah.that worked.if we multiply a unit vector n with a magnitude m, we should get a vector with magnitude m that points in the unit vector direction.right?(n*m)
i mistook vectors to points as u said.but cant get the diff bw them.! my maths $$anonymous$$cher would be proud of me.
so i understand iam not giving its initial position b+something.
Your answer
![](https://koobas.hobune.stream/wayback/20220612214130im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make Gameobject Stand On Surface Facing Certain Direction 0 Answers
List and store vector3 of game objects with tag 1 Answer
Finding difference between gameObject's x coordinate according to one object's transform 1 Answer
Moving one GameObject to another, and Vector Normalization issues 1 Answer
charachters stand next to each other 0 Answers