Math Class. Getting coordinates in front of the player.

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
User avatar
Creep
CJ Worshipper
CJ Worshipper
Posts: 268
Joined: August 31st, 2006, 10:32 am
Location: Hungary

Math Class. Getting coordinates in front of the player.

Post by Creep » September 2nd, 2012, 4:18 pm

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 :)
Last edited by Creep on September 2nd, 2012, 6:20 pm, edited 1 time in total.
Image

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

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

Post by Nekoneko » September 2nd, 2012, 6:14 pm

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 );

User avatar
Creep
CJ Worshipper
CJ Worshipper
Posts: 268
Joined: August 31st, 2006, 10:32 am
Location: Hungary

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

Post by Creep » September 2nd, 2012, 6:22 pm

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
Image

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests