There doesn't seem to be a normalize function for Vector2's.
If I use a 2D vector inside the Vector3.Normalize static function, will that deal with it happily? Similarly, if I set a 2D vector to a 3D one, how will it handle it? Just pass back the first two components (X and Y)?
i.e. is this valid:
Vector2 delta = vTo - vFrom;
//... ignore delta mangitude == 0.0f
Vector2 direction = Vector3.Normalize( delta );
Thanks in advance!
It seems like it does work. I can't see by which mechanism this is possible (perhaps an auto-conversion). You could also use the following (it is probably faster):
Vector2 direction = delta.normalized;
You can help yourself with the .magnitude field, which is available for Vector2, so there will be (probably) no internal casting.
Vector2 delta = vTo - vFrom;
Vector2 direction = delta/delta.magnitude; // maybe test this for ==0 first
EDIT: To complete the answer: Vector3.Normalize(v) modifies and normalizes vector v. It does not return anything, so you can't use it at all here. Either use this method I described here, or use delta.normalized, as Herman Tulleken suggests.
Did you try casting? You cannot implicitly cast from Vector3 to Vector2 because you will lose the z value.
Vector2 direction = (Vector2)Vector3.Normalize(delta);