Is there a difference between Vector3.Normalize() and instance.Normalize()?

Hi guys,

First, thanks for this amazing project. Really making progress with my game. I wanted to debug my terrain manager, so decided to add a “centre of tile” line that would show the centre of the tile, adjusted by it’s normal.

After generating normals for the vertices for a tile, I set the tile normal, and normalised it using:


However, I noticed the magnitude of Centre was not 1, and the length of the resultant vector was 600f (causing there to be a web of lines on the screen). I changed the code to:

tile.Centre = Vector3.Normalize(tile.Centre);

And it correctly had a magnitude of “1” and rendered correctly.

Did I done goof?

tile.Centre is a {get;set;} property, right?

I believe @nkast is on the right track here. If Centre is a property, it is returning a copy of the vector. You are then normalizing this copy, which is then discarded. In the second case, you are taking a copy of the vector, passing that copy to Vector3.Normalize and assigning the return value back to the property, which is correct. If Centre was a field and not a property, then the first case would work as expected.

1 Like

Doh, well that’s a schoolboy error for sure. Years of professional experience and I totally missed that. :smile:
Thanks guys.