View Single Post
Old 09-10-2009, 04:43 PM   #2
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
Heh, mmk...

Here's a bit of code I used to teleport you roughly where you're looking at.
I'm sure you could tweak it around a bit for what you want =P

Code:
static void teleport( gentity_t *ent ) {
	trace_t	tr;
	vec3_t	fPos, telepos;
	int i;

	//We want to obtain where they're looking at - This does it for us =]
	AngleVectors(ent->client->ps.viewangles, fPos, NULL, NULL);
	for (i=0; i < 3; i++)
		fPos[i] = ent->client->ps.origin[i] + fPos[i]*Q3_INFINITE;

	//Perform the trace, the tr.endpos will hold the vec3_t of where it collided with something
	trap_Trace(&tr, ent->client->ps.origin, 0, 0, fPos, ent->s.number, MASK_OPAQUE|CONTENTS_SOLID|CONTENTS_BODY|CONTENTS_ITEM|CONTENTS_CORPSE );

	//If we teleported directly to tr.endpos, we'd end up in a wall, so do a bit of vector math and we're safe
	VectorMA(tr.endpos, 32, tr.plane.normal, telepos);

	//Beam me up, scotty!
	TeleportPlayer( ent, telepos, ent->client->ps.viewangles );
}

-=*Raz0r*=- is offline   you may: quote & reply,