Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Vector Math? How can I determine an AI/Actor's forward velocity
Vector Math? How can I determine an AI/Actor's forward velocity
2004-10-02, 7:06 AM #1
It sounds simple enough. My first thought was GetThingVel, coupled with VectorY would get me what I wanted. Rbots even used this code for jump determination.

However, It appears after some testing that while that does get the velocity of a thing...it doesn't actually get the velocity relative to the things look vector. Rather, the velocity is just relative to the map coordinates. (which, really, is what it should do. :P)

With the player is cake. You just use GetThingThrust(). But Actors do not have thrust in this manner. All values of the actors thrust return 0 so they aren't useful here.

I'm going to play with it some more...maybe some of the code in force_farsight will provide some direction.
-El Scorcho

"Its dodgeball time!" -Stormy Waters
2004-10-02, 7:18 PM #2
I'm assuming that by "forward velocity" you mean "forward speed." It's pretty simple to do, just a little hard to visualize:

First you need to get values for the target's looking vector (lvec), the target's velocity vector (vvec), and the target's speed. So using the player, we'll do:

Code:
player=GetLocalPlayerThing();
lvec=GetThingLVec(player);
vvec=GetThingVel(player);
speed=VectorLen(vvec);


Now that we have the basics, we need the cosine (or dot in this case) of the lvec and vvec (the cosine will show us how far apart the two vectors are looking). We will have to normalize vvec so that it has a length of one because we need only vvec's direction for the cosine operation. Then we'll multiply the speed times the cosine and we have our frontSpeed:

Code:
dot=VectorDot(lvec, VectorNorm(vvec));
frontSpeed=speed * dot;
print("your front speed is: ");
printflex(frontSpeed);


And there you have it. ;)
Historians are the most powerful and dangerous members of any society. They must be watched carefully... They can spoil everything. - Nikita Khrushchev.
Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god. - Jean Rostand.
2004-10-03, 6:24 AM #3
Thanks a lot Centrist! I knew it was something like that, but I just couldn't see exactly how to make it happen so I was stuck.
-El Scorcho

"Its dodgeball time!" -Stormy Waters
2004-10-03, 10:35 AM #4
Sure. ;)
Historians are the most powerful and dangerous members of any society. They must be watched carefully... They can spoil everything. - Nikita Khrushchev.
Kill one man, and you are a murderer. Kill millions of men, and you are a conqueror. Kill them all, and you are a god. - Jean Rostand.

↑ Up to the top!