Game Development Community

Small math question.

by Kevin Mitchell · in Torque 3D Professional · 04/17/2012 (10:49 am) · 4 replies

Okay so apparently I've worked so hard that I've forgotten my math...

I have a Starting Position and a Target Position.

Lets say:

"20 60 133"

and Ending:

"66 96 125"

Now I'm shooting a projectile from the Start Position.

But for a projectile to shoot you have to give it a aim direction:

The examples I've seen shows:


" 1 0 0"
"-1 0 0"
" 0 1 0"
" 0 -1 0"
" 0 0 1"
" 0 0 -1"

Which work great for stationaries.
It looks like the direction is X Y Z based and the min and max range from -1 to 1.

I know I can do VectorSub or VectorAdd. This gives me a calculated difference to the target but its direction values are higher than any example I've found.

How can I translate this into a +-1 for the projectile to shoot at the current target.

Thanks for your help.




#1
04/17/2012 (11:57 am)
I'm no math expert myself, but don't you just normalize the Vector?
#2
04/17/2012 (11:59 am)
I remember making a "magic bullet" resource, the answer is probably in there.
#3
04/17/2012 (12:36 pm)
There is a function for vector normalization:
Quote:
VectorF VectorNormalize ( VectorF v )
Brings a vector into its unit form, i.e. such that it has the magnitute 1.

Parameters:
v The vector to normalize.
Returns:
The vector v scaled to length 1.
Example:
//-----------------------------------------------------------------------------
//
// VectorNormalize( %a );
//
// The normalized vector a, (ax, ay, az), is:
//
//     a^ = a / ||a||
//        = ( ax / ||a||, ay / ||a||, az / ||a|| )
//
//-----------------------------------------------------------------------------

%a = "1 1 0";
%l = 1.414;

// %r = "( 1 / 1.141, 1 / 1.141, 0 / 1.141 )";
// %r = "0.707 0.707 0";
%r = VectorNormalize( %a );
#4
04/17/2012 (2:44 pm)
I want to hug you all. I did not know normalize vector did this.