Advertisement Jump to content
Sign in to follow this  

Why to normalize in Unity?

This topic is 1598 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A question about this code in a unity pong tutorial:

// Give the ball some initial movement direction
rigidbody2D.velocity = * speed;


Why do we have to normalize the vector if its already one?



Share this post

Link to post
Share on other sites

Due to the documentation, is the vector (1,1) which has the length sqrt(1^2 + 1^2) = 1.4142 approx., so it is not of unit length.


EDIT. For the case you do not know: The normalization ensures that the length of the vector is 1, not that all of its components are 1. So, in this case, the result of normalization would be approximately

    (1,1) / length( (1,1) ) = (1,1) / 1.41412 = (0,707,0.707)


This step ensures that the velocity vector has a length equal to the value of speed. Otherwise its length would depend on the actual direction, so you would have higher speed in diagonal directions than in principal directions.

Edited by haegarr

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!