Posted By: SirCamaris
c_trace and level geometry detection? - 12/25/09 03:33
I set up movement code so that the player moves forward in increments of 256 quants. I'm trying to prevent movement altogether when c_trace recognizes a wall 128 quants away. The problem is that I don't know how to detect regular walls in c_trace. Code sample: c_trace (player, vector(player.x + 128, player.y, player.z), Use_Box > 0); // where "> 0" returns distance to player. if (hit.entity = NULL) {player.x = 0;} //end of code sample. I tried many variations on this code sample but none seem to work. Please help. If any further info needs to be provided, let me know. Thank you.
Posted By: Superku
Re: c_trace and level geometry detection? - 12/25/09 21:55
Have a look at the syntax of c_trace in the manual.
c_trace (player.x, vector(player.x + 128, player.y, player.z),USE_BOX);
if(trace_hit) { don't move }
else { move }
To be on the safe side (the wall could be f.i. 128.1 quants away, depending on your movement code) you could increase the distance of your trace instruction. If c_trace hits something it will return the distance to the object/ wall.
result = c_trace (player.x, vector(player.x + 150, player.y, player.z),USE_BOX);
if(trace_hit && result < 129 or some other value) { don't move }
else { move }
Posted By: SirCamaris
Re: c_trace and level geometry detection? - 12/26/09 20:40
Superku,
Thanks for the reply. When placing the mouse over c_trace in SED, it displayes info on how c_trace is used. It says that c_trace modifies trace_hit, where a value greater than zero is the c_trace distance from player to object. When I place the cursor over trace_dist after typing it in though, there is no description on how it is used, which leads me to believe that it is not being used when the code is executed. My question is if this variable is predefined, why wouldn't a description show on how to use it? Also, may this have something to do with me saving the document as .c instead of .wdl? Would trace_dist work in one over the other? Thank You.
Posted By: Superku
Re: c_trace and level geometry detection? - 12/26/09 21:55
Whether a description appears or not, that does not mean a thing.
After a trace instruction the variable trace_hit is 1 (something hit) or 0 (else), it is not set to different values than 1/0.
Have a look at the following example:
function a_useless_function {
// ...
return 523;
}
...
result = a_useless_function();
Now result is 523 and no predefined variable has been changed to return the value.
It is exactly the same with c_trace:
result = c_trace(some parameters);
or
var distance;
distance = c_trace(some parameters);.
Posted By: SirCamaris
Re: c_trace and level geometry detection? - 12/27/09 21:42
This is some of what I tried so far:
c_trace(player.x, vector(player.x + 128, player.y, player.z), IGNORE_ME);
if (trace_hit = 1)
{c_move(player, vector(0,0,0)nullvector, GLIDE);}
else {move_forward();}
trace_hit appears to be working because the coordinates that I put in reldist vector in c_move get executed. What is odd however, is that when the level starts, the first wall in front of the player is more than 256 quants away, so trace_hit should really be 0. I'm thinking this may have something to do model placement, although in Wed, the model is within the corridor and isn't touching anything.
Thank you again for your continued help.
Posted By: Rei_Ayanami
Re: c_trace and level geometry detection? - 12/27/09 22:11
well, if you don't program a side scroller, you must put the c_trace in the directio of the player:
c_trace(player.x, vector(player.x + 128*cos(player.pan)*cos(player.tilt), player.y+128*sin(player.pan)*cos(player.tilt), player.z+128*sin(player.tilt)), IGNORE_ME);
this should work
Posted By: SirCamaris
Re: c_trace and level geometry detection? - 01/09/10 01:18
Thank you Rei; It took me a while to figure it out, but you are right. I needed to put c_trace in the direction of the player. The only other thing I had to add was USE_BOX.
Posted By: SirCamaris
Re: c_trace and level geometry detection? - 01/09/10 01:27
Superku
I was able to get c_trace to work properly by building on your and Rei's comments. Here is the final version:
if (c_trace (player.x, vector(player.x + 128*cos(player.pan),
player.y + 128*sin(player.pan), player.z + 0), IGNORE_ME | USE_BOX) > 0)
{c_move (player, vector(0, 0, 0), nullvector, GLIDE);}
else
{move_forward();}
Thanks again for your help.