How do you get a vector from your left, right, or behind?
by Chris Cain · in Torque Game Engine · 01/16/2004 (7:31 pm) · 4 replies
I already know how to get the vector from infront of you... but I was wondering how to get a vector from either side or behind you.... I'm planning on using the "setvelocity" function to instantly make the player move one way or the other using functions...
#2
01/17/2004 (11:15 am)
Thank you very much!
#3
%vec=%player.getEyeVector();
%zAngle=90*PI/180; //has to be rads
%matrix=MatrixCreateFromEuler( "0 0" SPC %zAngle);
%resultVector=MatrixMulVector(%matrix, %vec);
%player.setVelocity (or apply impulse?) (%vec);
The important call is the matrixfromeuler. The z part of that will do the cardinal directions that you need.
peace,
-s
01/21/2004 (10:33 am)
I have this code implemented... I will send it to you, but I got it from some other resource on here as well. My only prob is that it doesnt work over the network because I am checking the $mvLeftAction, etc vars and the body of this dodge move is declared on the server, as its an "onUse" of an item. You need to send a message or do something like that to get it to work for clients using the $mvXXX stuff. Here's the rough code:%vec=%player.getEyeVector();
%zAngle=90*PI/180; //has to be rads
%matrix=MatrixCreateFromEuler( "0 0" SPC %zAngle);
%resultVector=MatrixMulVector(%matrix, %vec);
%player.setVelocity (or apply impulse?) (%vec);
The important call is the matrixfromeuler. The z part of that will do the cardinal directions that you need.
peace,
-s
#4
http://www.garagegames.com/mg/forums/result.thread.php?qt=15604
01/21/2004 (10:35 am)
Also check this one that was just posted out:http://www.garagegames.com/mg/forums/result.thread.php?qt=15604
Torque Owner Michael Higginbotham
[url]http://www.gamedev.net/reference/articles/article1832.asp[\url]
Torque uses a right hand coordinate system where the x-y plane is the "ground" and the positive z axis points straight up.
If one were looking down the x axis your vector would be [1,0,0], down the y axis [0,1,0] and up the z axis the vector would be [0,0,1]. Since a vector is both a direction and a magnitude, if you were moving along the x axis at 10 units of speed, the velocity vector would be [1,0,0]. (<- Edit, this vector should be [10,0,0])
Unfortunately, once you start adding in rotations, the math starts getting more complicated to get the resultant vector. Look at the section at the end of the tutorial about the rotation matrices for forming velocity vectors with arbritrary rotations.
Hope this helps.