1 registered members (TipmyPip),
18,449
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: c_trace
[Re: 3run]
#328432
06/13/10 07:32
06/13/10 07:32
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Errr ... Dont really know what you mean, but is this it?
...
while(me)
{
...
//calculate 'START-of-trace' vectors
vec_set(s_leftV, vector(0,0, my.min_z)); //local co-ord of feet
vec_rotate(s_leftV, my.pan); //rotate to players facing direction
vec_add(s_leftV, my.x); //position 'around' player
vec_set(s_backV, vector(0,0, my.min_z)); //local co-ord of feet
vec_rotate(s_backV, my.pan); //rotate to players facing direction
vec_add(s_backV, my.x); //position 'around' player
vec_set(s_rightV, vector(0,0, my.min_z)); //local co-ord of feet
vec_rotate(s_rightV, my.pan); //rotate to players facing direction
vec_add(s_rightV, my.x); //position 'around' player
//
//calculate 'END-of-trace' vectors
vec_set(e_leftV, vector(0,-500, my.min_z)); //trace distances (from feet)
vec_rotate(e_leftV, my.pan); //rotate to players facing direction
vec_add(e_leftV, my.x); //position 'around' player
vec_set(e_backV, vector(-500,0, my.min_z)); //trace distances (from feet)
vec_rotate(e_backV, my.pan); //rotate to players facing direction
vec_add(e_leftV, my.x); //position 'around' player
vec_set(e_rightV, vector(0,500, my.min_z)); //trace distances (from feet)
vec_rotate(e_rightV, my.pan); //rotate to players facing direction
vec_add(e_leftV, my.x); //position 'around' player
c_trace(s_leftV, e_leftV, IGNORE_ME); /* debugging --> */ draw_line3d(s_leftV, NULL, 100); draw_line3d(e_leftV.x, vector(0,255,0), 100);
c_trace(s_backV, e_backV, IGNORE_ME); /* debugging --> */ draw_line3d(s_backV, NULL, 100); draw_line3d(e_backV.x, vector(0,0,255), 100);
c_trace(s_rightV, e_rightV, IGNORE_ME); /* debugging --> */ draw_line3d(s_rightV, NULL, 100); draw_line3d(e_rightV.x, vector(255,0,0), 100);
//
//
wait(1);
}
...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: c_trace
[Re: 3run]
#328555
06/13/10 21:34
06/13/10 21:34
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Before you post the demo, let us try a couple of things...
But firstly, now I am more awake, I notice that all 3 of the 'trace-from' vectors will always be the same value, because they are the same point. so cut that down to one calculation and use it in all three traces to save CPU.
Secondly, when you say you are 'playing with the distances', what do you mean? Revember the trace-to vectors MUST have thier Z value = my.min_z before the vec_rotate and vec_add otherwise the trace will start going 'uphill' or 'downhill' from the feet.
Or did you want the traces to go left/right/back from his feet but scan parallel to the ground?
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: c_trace
[Re: 3run]
#328564
06/13/10 23:14
06/13/10 23:14
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
This is something I threw together quickly. It traces behind and to the sides of an object, relative to it's pan. I used a similar code to draw my player's axis for debug purposes. Note : -you will need a temporary vector "temp_vec" defined somewhere. -trace_dist is how far away from the object the trace will scan. -The result will be 0 unless you are near something (like my screenshot below I had walls to all sides of the object). -I used the z value of " my.z + my.min_z + 1 ", which is the base of the object's collision hull + 1 (upward), the + 1 will keep the trace above ground level (hopefully).
var trace_dist = 100 // distance of trace
///////////////
//trace behind
vec_set(temp_vec, vector(my.x-(trace_dist*cos(my.pan)), my.y-(trace_dist*sin(my.pan)), my.z+my.min_z+1) );
c_trace(vector(my.x,my.y,my.z + my.min_z+1),temp_vec, IGNORE_ME | IGNORE_PASSABLE); //TRACE
//trace left
vec_set(temp_vec, vector(my.x-(trace_dist*cos(my.pan-90)), my.y-(trace_dist*sin(my.pan-90)), my.z+my.min_z+1) );
c_trace(vector(my.x,my.y,my.z + my.min_z+1),temp_vec, IGNORE_ME | IGNORE_PASSABLE); //TRACE LEFT
//trace right
vec_set(temp_vec, vector(my.x-(trace_dist*cos(my.pan+90)), my.y-(trace_dist*sin(my.pan+90)), my.z+my.min_z+1) );
c_trace(vector(my.x,my.y,my.z + my.min_z+1),temp_vec, IGNORE_ME | IGNORE_PASSABLE); //TRACE
same code, with added code to draw lines.
var trace_dist = 100 // distance of trace
///////////////
//trace behind
vec_set(temp_vec, vector(my.x-(trace_dist*cos(my.pan)), my.y-(trace_dist*sin(my.pan)), my.z+my.min_z+1) );
c_trace(vector(my.x,my.y,my.z + my.min_z+1),temp_vec, IGNORE_ME | IGNORE_PASSABLE); //TRACE
// draw line green
vec_set(temp_vec, vector(my.x-(result*cos(my.pan)), my.y-(result*sin(my.pan)), my.z+my.min_z+1) );
draw_line3d(my.x,COLOR_GREEN,0);
draw_line3d(vector(my.x,my.y,my.z+my.min_z),COLOR_GREEN,100);
draw_line3d(temp_vec,COLOR_GREEN,100);
draw_line3d(temp_vec,COLOR_GREEN,0);
//
//trace left
vec_set(temp_vec, vector(my.x-(trace_dist*cos(my.pan-90)), my.y-(trace_dist*sin(my.pan-90)), my.z+my.min_z+1) );
c_trace(vector(my.x,my.y,my.z + my.min_z+1),temp_vec, IGNORE_ME | IGNORE_PASSABLE); //TRACE LEFT
// draw line red
vec_set(temp_vec, vector(my.x-(result*cos(my.pan-90)), my.y-(result*sin(my.pan-90)), my.z+my.min_z+1) );
draw_line3d(my.x,COLOR_RED,0);
draw_line3d(vector(my.x,my.y,my.z+my.min_z),COLOR_RED,100);
draw_line3d(temp_vec,COLOR_RED,100);
draw_line3d(temp_vec,COLOR_RED,0);
//
//trace right
vec_set(temp_vec, vector(my.x-(trace_dist*cos(my.pan+90)), my.y-(trace_dist*sin(my.pan+90)), my.z+my.min_z+1) );
c_trace(vector(my.x,my.y,my.z + my.min_z+1),temp_vec, IGNORE_ME | IGNORE_PASSABLE); //TRACE
//draw line blue
vec_set(temp_vec, vector(my.x-(result*cos(my.pan+90)), my.y-(result*sin(my.pan+90)), my.z+my.min_z+1) );
draw_line3d(vector(my.x,my.y,my.z+my.min_z),COLOR_BLUE,0);
draw_line3d(vector(my.x,my.y,my.z+my.min_z),COLOR_BLUE,100);
draw_line3d(temp_vec,COLOR_BLUE,100);
draw_line3d(temp_vec,COLOR_BLUE,0);
//
Last edited by Rich; 06/13/10 23:43.
A8 com / A7 free
|
|
|
|