Inside3D!
     

Traceline

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
ajay



Joined: 29 Oct 2004
Posts: 295
Location: Swindon, UK

PostPosted: Sun Jun 13, 2010 11:24 am    Post subject: Traceline Reply with quote

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
_________________
my site
Back to top
View user's profile Send private message MSN Messenger
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Jun 13, 2010 12:03 pm    Post subject: Reply with quote

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).
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Arkage



Joined: 19 Nov 2009
Posts: 27

PostPosted: Sun Jun 13, 2010 3:41 pm    Post subject: Reply with quote

For a usage example I think the flash light tutorial is a good one. http://www.inside3d.com/showtutorial.php?id=119
Back to top
View user's profile Send private message
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Sun Jun 13, 2010 4:35 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message MSN Messenger
ajay



Joined: 29 Oct 2004
Posts: 295
Location: Swindon, UK

PostPosted: Sun Jun 13, 2010 5:27 pm    Post subject: Reply with quote

Thanks both, I'm getting ever so slightly closer. One (hopefully last) more question; how do you do a traceline downwards?
_________________
my site
Back to top
View user's profile Send private message MSN Messenger
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Jun 13, 2010 5:45 pm    Post subject: Reply with quote

use the same x and y coords for the two points, with the second z coord lower down?
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
ajay



Joined: 29 Oct 2004
Posts: 295
Location: Swindon, UK

PostPosted: Sun Jun 13, 2010 7:00 pm    Post subject: Reply with quote

More detail. Extract from what I'm doing:
Code:

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?
_________________
my site
Back to top
View user's profile Send private message MSN Messenger
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Sun Jun 13, 2010 9:34 pm    Post subject: Reply with quote

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
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Jun 13, 2010 10:20 pm    Post subject: Reply with quote

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).
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
Urre



Joined: 05 Nov 2004
Posts: 1073
Location: Sweden

PostPosted: Mon Jun 14, 2010 4:16 am    Post subject: Reply with quote

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...
_________________
Look out for Twigboy
Back to top
View user's profile Send private message Visit poster's website
LordHavoc



Joined: 05 Nov 2004
Posts: 243
Location: western Oregon, USA

PostPosted: Mon Jun 14, 2010 5:12 am    Post subject: Reply with quote

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:

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)
Back to top
View user's profile Send private message Visit poster's website
ajay



Joined: 29 Oct 2004
Posts: 295
Location: Swindon, UK

PostPosted: Mon Jun 14, 2010 4:56 pm    Post subject: Reply with quote

Thanks for all your help, I've gone with this:
Code:
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.
_________________
my site
Back to top
View user's profile Send private message MSN Messenger
Wazat



Joined: 15 Oct 2004
Posts: 732
Location: Middle 'o the desert, USA

PostPosted: Wed Jun 16, 2010 12:45 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group