Page 1 of 1

Math Class. Getting coordinates in front of the player.

Posted: September 2nd, 2012, 4:18 pm
by Creep
I want to share this snippet, because it took some hours from my life, to solve this simple Math problem.
With this script, you can get the position in front of you, from your angles.

front = anglesToForward( self getplayerangles() );
front = (front[0] * 50, front[1] * 50, front[2] * 50);
trace = bulletTrace( self.origin, front, false, self );

iprintlnbold(trace["position"]);


I used it for a gravity gun. You get bounce, from the front everywhere.

http://www.xfire.com/video/5a7cce/

Greetings :)

Re: Math Class. Getting coordinates in front of the player.

Posted: September 2nd, 2012, 6:14 pm
by Nekoneko
Creep wrote: front = anglesToForward( self getplayerangles() );
vec = (front[0] * 50, front[1] * 50, front[2] * 50);
trace = bulletTrace( self.origin, front, false, self );

iprintlnbold(trace["position"]);
it is pretty simple, but you have one thing messed up:
trace = bulletTrace( self.origin, front, false, self );
should be:
trace = bulletTrace( self.origin, self.origin + vec, false, self );

Re: Math Class. Getting coordinates in front of the player.

Posted: September 2nd, 2012, 6:22 pm
by Creep
Nekoneko wrote: it is pretty simple, but you have one thing messed up:
trace = bulletTrace( self.origin, front, false, self );
should be:
trace = bulletTrace( self.origin, self.origin + vec, false, self );
Oups, I used function in my script and the vec variable doesn't exist in this version.
I've corrected it, the second line is for 'front' variable. :)

Yes it's simple, but I'm not familiar with cod2 script functions, yet :/

Thanks