View Single Post
Old 03-24-2010, 02:38 PM   #3
XycaleTh's Avatar
Join Date: Apr 2006
Location: UK
Posts: 67
Let's start with the function definition first:
trap_Trace (result, startpos, mins, maxs, endpos, skipnumber, collisionflags)
result: the trace_t - this is how the function returns the results of the trace.
startpos: where you want to start tracing from.
mins and maxs: like the mins/maxs of a player's bounding box. In your case, you want them to be the same as your item's bounding box.
endpos: where you want the trace to finish.
skipentity: the entity number you want to avoid collision detection against.
collisionflags: tells the function what sort of collision boxes you want to collide against.

Then we want to determine the result of this trace (I've taken this from q_shared.h):
typedef struct {
	byte		allsolid;	// if true, plane is not valid
	byte		startsolid;	// if true, the initial point was in a solid area
	short		entityNum;	// entity the contacted sirface is a part of

	float		fraction;	// time completed, 1.0 = didn't hit anything
	vec3_t		endpos;		// final position
	cplane_t	plane;		// surface normal at impact, transformed to world space
	int			surfaceFlags;	// surface hit
	int			contents;	// contents on other side of surface hit
} trace_t;
Each of the fields are explained in the code already, but I can add a bit more information:

allsolid: true if the object you were testing was inside a solid the entire trace.
startsolid: true if the object you were testing started inside another object.
entityNum: the entity number of the object that was collided against - this will be ENTITYNUM_WORLD for something that's not linked to an entity, e.g. a plain brush.
fraction: will be in the range 0.0 - 1.0, and indicates how far along the trace a collision took place (if any). obviously if fraction == 1.0, then the trace reached the end point without any collision.
endpos: the point of collision (if any)
plane: information about the plane which the collision took place against - this holds information such as the plane's equation.
surfaceFlags: the surface flags of the object collided against - I think this is for testing air-water/lava transitions?
conents: the colliding object's contents flags, e.g. MASK_PLAYERSOLID, MASK_SHOT, etc.

The biggest problem i have is that occasionally while moving an item with the force it gets stuck inside the floor or the wall, and my trap_Trace() function is not determining the correct result, thus the sound engine keeps playing the *bounce* sound as if the item is bouncing, but it isn't, it ricocheting back and forth off the top and bottom of the inside of the map face.....however, in some circumstances the startsolid is ill-flagged in this attempts
It might be that because it's touching the ground, it's registering as starting in a solid. I'm not sure what the trace function would do this in case - whether it detects the first collision AFTER the starting point, regardless of if it's already colliding with something, or whether it takes the first collision to be the result. If it's the first case (and you would be able to test it, just check if tr.fraction is 0.0 when tr.startsolid is true), then you could only check for tr.fraction != 1.0.

Last edited by XycaleTh; 03-24-2010 at 02:44 PM.
XycaleTh is offline   you may: quote & reply,