Well a normal is essentially a direction in either 2D or 3D space. Normals are awesome because you can find which way an enemy is facing and normalize that direction and then scale the normal by a scalar value, say 'speed', and they'll go off in that direction with a scaled normal which is then considered their velocity.
The reason that formula is because a Normal is defined by: A vector whose magnitude is equal to one and x, y and z's are less than 1 and greater than 0.
It comes down to simple math.
double length = sqrt(x*x+y*y+z*z);
That's the same formula as the pythagorean theorem
a^2+b^2+z^2 = c^2
After you've calculated the length, or the 'Magnitude' of this vector you divide it's parts by this length to normalize them between 0 and 1
1 2 3
|
x = x/length;
y = y/length;
z = z/length;
|
That'll give you the x, y and z values who's magnitude is exactly 1. To break down the scaling part think about this:
assume the values x, y, z are normalized
1 2 3 4 5
|
scale = 10;
x * scale;
y * scale;
z * scale;
|
the magnitude of this vector will be 10 and its compnents scaled appropriately to make it possible.
I wish I had time to illustrate by drawing a picture. But, I'm currently pulling an all nighter to study for finals :/