Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Editing traceline

From Quake Wiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
''void'' '''traceline'''(''vector'' start, ''vector'' end, ''float'' collisionType, ''entity'' ignore)
+
====Syntax:====
 +
<code>void traceline(vector v1, vector v2, float collisionType, entity ignore)</code>
  
== Usage ==
+
This function traces a line between v1 and v2 and sets many global variables depending on the results of the trace.
Fires out a line from the starting position to the ending position, colliding with anything based on the passed collision type. Sets the following globals:
+
====Parameters:====
*'''trace_allsolid'''
+
:<code>v1</code> - The start point of the trace
:If <code>TRUE</code>, the trace was stuck entirely in solids.
+
:<code>v2</code> - The end point of the trace
*'''trace_startsolid'''
+
:<code>collisionType</code> - How the trace interacts with other entities.  0 makes it collide with both the world and solid entities' bounding box.  1 makes it not collide with monsters (solid entities with the FL_MONSTER flag set on .flags).  2 makes the trace extra wide against monsters.
:If <code>TRUE</code>, the trace started inside of a solid.
+
====Returns:====
*'''trace_fraction'''
+
:void
:The fraction of the total distance the trace traveled before stopping. Ranges from [0, 1].
+
====Global variables affected:====
*'''trace_endpos'''
+
:<code>float trace_allsolid</code> - (?)
:The position the trace stopped.
+
:<code>float trace_startsolid</code> - (?)
*'''trace_plane_normal'''
+
:<code>float trace_fraction</code> - The fraction of the total length of the vector v2 - v1 that was traced before the trace hit an obstacle.
:The normal of the plane that the trace hit.
+
:<code>vector trace_endpos</code> - The coordinates of the end point of the trace. If the trace did not hit anything, than trace_endpos = v2, otherwise it will report the position where the trace hit an obstacle.
*'''trace_plane_dist'''
+
:<code>vector trace_plane_normal</code> - The normal of the plane that was hit by the trace.
:The distance from the world origin of the plane that the trace hit. This is d in the plane equation ax + by + cz + d = 0.
+
:<code>float trace_plane_dist</code> - The distance of the plane to the world origin (?)
*'''trace_ent'''
+
:<code>entity trace_ent</code> - The entity that was hit by the trace (if nothing was hit, returns world).
:The entity that the trace hit.
+
:<code>float trace_inopen</code> - If the trace is in open air (?)
*'''trace_inopen'''
+
:<code>float trace_inwater;</code> - If the trace is in water (?)
:If <code>TRUE</code>, the trace traveled through open air.
 
*'''trace_inwater'''
 
:If <code>TRUE</code>, the trace traveled through a liquid.
 
  
=== Parameters ===
 
*''start''
 
:The starting position of the trace.
 
*''end''
 
:The destination position of the trace.
 
*''collisionType''
 
:The type of entities considered valid when checking collision. Can be one of the following:
 
:*<code>0</code> (Collide with everything)
 
:*<code>1</code> (Only collide with entities that have a solid type of <code>SOLID_BSP</code>)
 
:*<code>2</code> (Collide with everything but use an extended pseudo bounding box against entities with the <code>FL_MONSTER</code> flag)
 
*''ignore''
 
:The entity to ignore collision of while tracing.
 
  
== Example ==
 
// This fires out a trace to see if it hit an entity. If it did, it deals damage
 
traceline(self.origin, self.origin + v_forward*128, 0, self);
 
if (trace_ent && trace_ent.takedamage != DAMAGE_NO)
 
    T_Damage(trace_ent, self, self, 20);
 
  
 
[[Category:QuakeC Function]]
 
[[Category:QuakeC Function]]

Please note that all contributions to Quake Wiki are considered to be released under the GNU Free Documentation License 1.3 or later (see Quake Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)