c_trace(VECTOR* from, VECTOR* to, var mode)
Sends a ray from the from position to the to
position and checks whether this ray hits an obstacle on its way. This is the
general instruction that is used by entities to detect their environment.
Alternatively to a ray, the detection probe can be an arbitrarily oriented ellipsoid, sphere, or flat disk, which covers all imaginable collision detection situations.
||Start position vector
||Target position vector
||Tracing mode, see below
The following mode flags can be combined:
||Ignores the me entity.
you entity (see remark)
and does not set the you pointer.
|| A7.05 Ignores all entities with FLAG2 set.
Ignores all passable blocks and entities.
Ignores passable model and sprite entities, but still detects passable maps, or passable terrain.
||Ignores all level blocks and terrains.
||Ignores all map entities.
||Ignores all models.
||Ignores all sprites.
a lower push or same group value than the given entity. For ignoring certain entity groups, call c_ignore before c_trace.
||Ignores the content of the trace origin. The function is
faster, but water entities (see above) are not detected.
Uses a polygonal hull of all target entities
even if their
POLYGON flag is not set.
Only for entities with a collision model, i.e. when the WED PASSABLE flag was not set and collision_mode not deactivated at entity creation.
Uses the bounding ellipsoid of the me
entity as a 'probe' for tracing, rather than a line. For this, the ellipsoid can be set up temporarily in the desired shape such as a sphere or a flat disk. A vertical trace with USE_BOX
can be used for detecting the distance to the ground,
keeping the entities' feet on the floor while ignoring small holes or grates.
||Enables EVENT_SHOOT triggering
of the hit entity.
||Enables EVENT_SONAR triggering
of the hit entity.
Retrieves the texture name,
vertex number, flags, brightness and light color of the hit surface, and sets it in the hit struct. Mutually
exclusive with USE_BOX.
If nothing was hit, the parameters are not set. The texture name can be used to check
the kind of floor below an entity.
||Distance to the hit polygon
of the target or of the next obstacle in the way.
||No polygon was hit.
||Information about the hit position, normal, texture, and entity A7.10 LC .
Modified when IGNORE_YOU is not set.
||Reflect the Flag1..Flag8 states of the hit surface.
||The fog / albedo value of the hit texture.
||EVENT_SHOOT or EVENT_SONAR (depends
The from position must be
outside an object in order to detect it.
- The bigger the distance between the to and from positions,
the more entities must be checked in the level, and the slower is the
function. Use as small a distance as possible.
For speeding up the function, use IGNORE flags (f.i. IGNORE_CONTENT, IGNORE_SPRITES etc.) whenever possible.
- In USE_BOX mode the speed of the function depends on the
ray volume, so it's especially important to keep the distance to
the to position
short. Don't set USE_BOX when a ray
trace would suffice.
- In USE_BOX mode the targets are always considered
polygonal (as if USE_POLYGON were set). The hull must not
intersect the target. The result delivered back gives the distance
from the hit point to the nearest point of the hull of the me entity.
If the entity touches the target in USE_BOX mode, 0 or a
very small distance value is delivered back. As 0 is also used
for indicating no hit, check the trace_hit value.
IGNORE_YOU can be used to prevent detection of a certain entity. !! A common mistake is setting the IGNORE_YOU flag but not setting the you pointer. This causes the detection to
return unwanted results
because you is modified by many functions, and thus can point to a different entity than expected.
For hitting an entity, trace to a point well inside the entity mesh, such as the entity center. !! A common mistake is using a vertex of the entity mesh for the trace target. This will miss the entity randomly because depending on its position or orientation, the trace ends just before touching the mesh surface.
For detecting which limb of an actor entity was hit, use the vertex number from the hit struct and retrieve the bone name with the ent_bonename function.
In some cases, faster functions can be used for the same purpose. For instance, the height above terrain at a certain position can also be calculated with the ent_nextvertex and ent_getvertex functions.
// test the floor texture - trace downwards 1000 quants below
if (hit.texname) printf("Floor texture: %s",hit.texname);
// place an entity onto the ground below
my.z = hit.z - my.min_z;
// look if the YOU enemy can be shot at from my position, and if yes, trigger its EVENT_SHOOT event
// trace 1000 units in direction the my entity is facing
c_ignore, ent_nextvertex, collision, hit,