Alternate c_trace mode

Posted By: Rich

Alternate c_trace mode - 07/23/08 12:11

Hi,

I wanted to suggest an alternate mode for c_trace, activated by flag, that could return the distance of the trace if nothing was hit (the old trace behavior).

An example where this would be useful would be a gravity script, where you trace below the object. Tracing -5000 below the object with USE_BOX set eats up a lot more resources than a trace of say -50. (-5000 is the value I most see used in examples for gravity).

So if I am tracing -50 below the entities location, and nothing is hit, than the result would be 50, not 0.

Thanks.
Posted By: xXxGuitar511

Re: Alternate c_trace mode - 07/23/08 14:49

I think it's easier to use trace results when it returns zero. Gives you a little more control...
Posted By: Pappenheimer

Re: Alternate c_trace mode - 07/23/08 16:23

you can use the 'trace_hit' instead:
Quote:
trace_hit Nonzero if c_trace hit something, otherwise 0.
from the online manual
Posted By: Rich

Re: Alternate c_trace mode - 07/23/08 16:37

Thanks Pappenheimer,

That will do it, but it doesn't return the distance, just 1 or 0. Though combining the result and this trace hit would work (example: if trace_hit = 1 and result < 1, the object is on the ground). I can honestly say that the last time I looked at c_trace I missed that.
Posted By: Pappenheimer

Re: Alternate c_trace mode - 07/23/08 16:47

Honestly, while already posting that your suggestion might be a good idea, I did a look into the manual and found this! wink
Posted By: tD_Datura_v

Re: Alternate c_trace mode - 07/24/08 11:57

I have seen planned traces of -999999, but if that is absurd, it is well placed here.

Instead of hard coded amounts, trace distances can be based on the actors size, min_z, max_z - min_z, etc. multiples.

Ignore this. It is erroneous.:
Code:
// ct = col trace
// n = var
ct_nResult += (ct_nResult == 0) * ct_nDist;  //?


Posted By: Xarthor

Re: Alternate c_trace mode - 07/26/08 10:37

The distance if nothing was hit is simply the distance between the VECTOR* from and VECTOR* to .. isn't it?

Code:
result = c_trace(trace_from,trace_to,IGNORE_ME);
if(!result)
{
  distance = vec_dist(trace_from,trace_to);
}
else { distance = result; }

Posted By: tD_Datura_v

Re: Alternate c_trace mode - 07/26/08 16:20

I should think so.
In the case of the overused gravity down trace, I believe something near enough to the distance is usually already available.

Doubly erroneous. Ignore x2.
Code:
// C-Script
var ct_nResult  = 0;
var ct_nDist = 0;
var ct_nDistD = 2;  // default in ENTITY units
var ct_nMode = 0;
//...
// set ct_nMode ?
vec_set(temp, my.x);
ct_nDist = (my.max_z - my.min_z) * ct_nDistD;
temp.z -= ct_nDist;
ct_nResult = c_trace(my.x, temp, ct_nMode);
ct_nResult += (ct_nResult == 0) * ct_nDist;	// without if construct


If ignoring properly, this shouldn't be seen.
Code:
distance = c_trace(trace_from, trace_to, trace_mode);
distance += (distance == 0) * vec_dist(trace_from, trace_to);  // wasteful

© 2024 lite-C Forums