Forum

Traceline

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

Traceline

Postby ajay » Sun Jun 13, 2010 11:24 am

Could someone suggest either a good tutorial re: using traceline or some existing code that I could study to get hang of how it works?
Cheers clever people,
ajay
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby Spike » Sun Jun 13, 2010 12:03 pm

call traceline. specify a start pos and an end pos. it tries tracing that line and stops if it hits anything.
sets the globals on return to say where it got to and what it hit.
nomonsters=true says ignore monsters, false means hit stuff.
it ignores passent and passent.owner (and ents where other.owner == passent)
globals trace_endpos = where it impacted. trace_fraction = fraction of distance traveled, between 0 and 1.
trace_plane_normal = the direction in which the surface it hit points.
trace_ent = the entity that got hit.
trace_startsolid = you're in a wall, dumbass.
trace_allsolid = wtf (quite frankly).

so yeah, trace start->end. if fraction is 1 it went the whole distance (or started solid, which allows you to move through solid stuff if you're already in said solid stuff).
if fraction < 1 then trace_ent says what it hits, either world or some ent.
trace_endpos is either the target (point2) or a point between point1 and 2, depending on the fraction.
trace_plane_normal is useless (still valid) for non-bsp ents.
will only hit solid stuff, no triggers. useful for bouncing projectiles off walls if you know the maths, but that's it.

look at the axe to see how it does its damage (W_FireAxe) (shotgun and lightning gun also use it, but in a more convoluted way).
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Arkage » Sun Jun 13, 2010 3:41 pm

For a usage example I think the flash light tutorial is a good one. http://www.inside3d.com/showtutorial.php?id=119
User avatar
Arkage
 
Posts: 66
Joined: Thu Nov 19, 2009 4:17 pm

Postby Wazat » Sun Jun 13, 2010 4:35 pm

Also note that if you start a traceline inside an entity that isn't the ignore ent (passent), then the traceline will automatically ignore all non-bsp entities. If you start inside a wall, I believe I remember the traceline ignoring everything including other walls.

So avoid starting a traceline inside a wall (which is easy to do by accident if you blindly adjust a position up/down/left/right before tracing). If you're starting a trace inside an entity (inside the player who is firing, inside the next monster chain lightning jumps from, etc), be sure to set that ent as the ignore ent/passent.

Couple of tricks to be aware of.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA

Postby ajay » Sun Jun 13, 2010 5:27 pm

Thanks both, I'm getting ever so slightly closer. One (hopefully last) more question; how do you do a traceline downwards?
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby Spike » Sun Jun 13, 2010 5:45 pm

use the same x and y coords for the two points, with the second z coord lower down?
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby ajay » Sun Jun 13, 2010 7:00 pm

More detail. Extract from what I'm doing:
Code: Select all
void() new_oildrum =
{
   local entity   oil, oil_spot, test;

   oil = spawn();
   oil_spot = find (world, classname, "player");

        traceline (oil_spot.origin , (oil_spot.origin+(v_forward * 100)), FALSE , self);

          test.origin = trace_endpos +(v_forward * -30);


(edit)

This first part works in that it stops the new drum being put through a vertical wall, it either cannot be placed or is moved back towards the player
The second part is what I'm failing with. What I'm trying to do is check whether its already in a solid (the floor) or floating above the ground, so I want to do is first test if test.origin is in a solid, (which I think I do with if (trace_setsolid == 1) return; ??) and if not trace straight down, once I hit a solid, go back up half the height of the drum and the set that as oil.origin.
But how do I trace down from test.origin and then go up, and am I overcomplicating it?
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby Urre » Sun Jun 13, 2010 9:34 pm

Wazat wrote:Also note that if you start a traceline inside an entity that isn't the ignore ent (passent), then the traceline will automatically ignore all non-bsp entities. If you start inside a wall, I believe I remember the traceline ignoring everything including other walls.

So avoid starting a traceline inside a wall (which is easy to do by accident if you blindly adjust a position up/down/left/right before tracing). If you're starting a trace inside an entity (inside the player who is firing, inside the next monster chain lightning jumps from, etc), be sure to set that ent as the ignore ent/passent.

Couple of tricks to be aware of.


Seriously? Either DarkPlaces works entirely different, or this is just not true :S
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby Spike » Sun Jun 13, 2010 10:20 pm

Wazat is correct.
If startsolid, then there's no point in checking the other nodes, because it cannot move anywhere anyway.
The bug is that with startsolid gives a fraction of 1 instead of 0.
Its not just DP.

ajay, you'll need to use tracebox instead of traceline, tbh, but that's an extension, a simple one, that could be implemented into most engines in 10 mins, but still an extension.
walkmove, droptofloor, and movetypes are the only real ways to trace boxes through the world without extensions. and they're not pretty.
tracebox works the same way as traceline, it just stops earlier, supposedly, based on the size of the box that is traced (q1bsps require specific known sizes).
Spike
 
Posts: 2892
Joined: Fri Nov 05, 2004 3:12 am
Location: UK

Postby Urre » Mon Jun 14, 2010 4:16 am

Actually no, DarkPlaces specificly lets traces get out of solids, and hit new solids on the way, even if startsolid is true. I depend heavily on this behavior...
I was once a Quake modder
User avatar
Urre
 
Posts: 1109
Joined: Fri Nov 05, 2004 2:36 am
Location: Moon

Postby LordHavoc » Mon Jun 14, 2010 5:12 am

Another correction - the parameter "nomonsters" is actually a movement type, the values in dpextensions.qc work with it, these are supported in stock Quake:
Code: Select all
float MOVE_NORMAL = 0; // standard trace, hits stuff (except ignoreent and anything whose .owner is equal to ignoreent)
float MOVE_NOMONSTERS = 1; // trace against SOLID_BSP only, hits world and doors
float MOVE_MISSILE = 2; // traces with enlarged box against monsters, used internally by MOVETYPE_FLYMISSILE and MOVETYPE_BOUNCEMISSILE but can be called from QC safely


(in DP there are additional types, see dpextensions.qc for info on that, I am only listing the stock Quake ones)
LordHavoc
 
Posts: 322
Joined: Fri Nov 05, 2004 3:12 am
Location: western Oregon, USA

Postby ajay » Mon Jun 14, 2010 4:56 pm

Thanks for all your help, I've gone with this:
Code: Select all
void() new_oildrum =
{
   local entity   oil, oil_spot;

   oil = spawn();
   oil_spot = find (world, classname, "player");

        traceline (oil_spot.origin , (oil_spot.origin+(v_forward * 100)), FALSE , self); //

          oil.origin = trace_endpos +(v_forward * -30);

   oil.origin_z = oil.origin_z + 150;

   oil.solid = SOLID_BBOX;
   oil.movetype = MOVETYPE_BOUNCE;
   oil.nextthink = time + 0.5;
   oil.think = new_oildrum_think;
};


What this gives me (well as tested so far) is a drum placement that:
- places the drum in front of the player, ready to explode or picked up and repositioned
- won't put it thru' or in a wall
- won't put it in or thru' the floor, whatever the person's view angle
- does have a lightly unnatural drop height, but to be honest it's a trade off, and sort of works. Once I get the actual 'weapon' drum mdoel working, I'll have a better idea of what it looks like.
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby Wazat » Wed Jun 16, 2010 12:45 am

When I figured out those traceline rules I was making my own portal gun. Shoot the gun at a wall and it would try to find a point on the other side of a wall to make a portal. If it found the other side and concluded there was enough space for a player, it would spawn a portal on each side. You could use the portal gun to walk through walls, floors, etc (touching one portal opening would teleport you to the other). I was actually reverse engineering a portal gun I'd seen early in my Quake development. I did it as a learning tool.

Discovering the startsolid issue was a major "aha" moment. Some engines have changed this behavior, but original quake will not let a traceline hit anything if it starts solid.
When my computer inevitably explodes and kills me, my cat inherits everything I own. He may be the only one capable of continuing my work.
Wazat
 
Posts: 771
Joined: Fri Oct 15, 2004 9:50 pm
Location: Middle 'o the desert, USA


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest