Forum

Trace Lines

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Trace Lines

Postby sniperz227 » Fri Dec 23, 2011 2:07 am

Hey I was wondering if someone could explain Tracelines to me.... im realizing for my mod i will have to use tracelines for some of my functions and it would be nice to know how they work and stuff so i know how to code them(ex. traceline to see if a bullet hit the player).

Thanks sniperz227
sniperz227
 
Posts: 112
Joined: Sat Apr 09, 2011 3:19 am

Re: Trace Lines

Postby Baker » Fri Dec 23, 2011 3:03 am

void (vector v1, vector v2, float nomonsters, entity forent) traceline = #16;
^^ vector v1 = starting point XYZ coords, vector v2 = ending point XYZ coords


trace_ent = what entity you hit
trace_endpos = vector where you hit ... vector = set of 3 coordinates X Y Z

// set by traceline / tracebox
float trace_allsolid;
float trace_startsolid;
float trace_fraction;
vector trace_endpos;
vector trace_plane_normal;
float trace_plane_dist;
entity trace_ent;
float trace_inopen;
float trace_inwater;

entity msg_entity; // destination of single entity writes

progs 1.06 weapon.qc ... http://inside3d.com/browse.php?show=weapons.qc
Code: Select all
/*
================
W_FireAxe
================
*/
void() W_FireAxe =
{        // Baker: a vector is a set of 3 floats representing X, Y, Z coordinates in the world                                                           
   local   vector   source;                                     // Baker: create vector to store attacking player location
   local   vector   org;                                        // Baker: create a vector to store successful hit location

   makevectors (self.v_angle); // Baker: Take player view angle and calculate the v_forward, v_left_ v_up
                                    // Baker: v_forward represents the "forward" component of where you are looking
                                    // Baker: so v_forward * 2 = 2 Quake feet in front of you, v_forward * 4 = 4 Quake feet in front of you
                                    // Baker: Quake "feet" or Quake units is the base measurement unit in mapping or in Quake as a whole

   source = self.origin + '0 0 16'; // Baker: self.origin = where attacker is ... add '0 0 16' because Axe is above middle of body
   traceline (source, source + v_forward*64, FALSE, self); // Baker: Trace through the world from axe location "source" to "source" + 64 Quake units forward
                                                                // Baker: For reference, the lightning gun = 600 units forward
                                                                // Baker: For reference, the shotgun looks like = 2048 units forward

   if (trace_fraction == 1.0) // Baker: For some reason if trace_fraction == 1.0, we didn't hit anything
      return;
   
        // Baker: We are only here if we hit something
       
   org = trace_endpos - v_forward*4;  // Baker: trace_endpos is where traceline said we hit, it is an X Y Z vector
                                            // Baker: Pull us back 4 Quake units

   if (trace_ent.takedamage) // Baker: trace_ent is the entity that we hit. 
   { // Baker: It can take damage, like a monster or a secret door so do blood stuff ...
      trace_ent.axhitme = 1;
      SpawnBlood (org, '0 0 0', 20);
      T_Damage (trace_ent, self, self, 20);
   }
   else
   {   // hit wall
      sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
      WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
      WriteByte (MSG_BROADCAST, TE_GUNSHOT);
      WriteCoord (MSG_BROADCAST, org_x);
      WriteCoord (MSG_BROADCAST, org_y);
      WriteCoord (MSG_BROADCAST, org_z);
   }
};



void (vector v1, vector v2, float nomonsters, entity forent) traceline = #16;

siska.robert wrote:Hi.
I've read specifications of traceline, and argument nomonster puzzles me. How does it recognize monsters from other entitites? :?


Spike wrote:it doesn't.
if that argument is 1, it will ignore all non-bsp objects, whether they're monsters or not.


Further infos: http://www.gamers.org/dEngine/quake/spe ... m#QC-BCOLS
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest