Q3 engine: world encroachment checks?

Locked
JPL
Posts: 13
Joined: Sun Nov 11, 2007 1:17 am

Q3 engine: world encroachment checks?

Post by JPL »

I'm working on something that gives the player an ability to teleport to arbitrary points in the world (think Translocator from UT). One problem I have to solve is that it's currently very easy to teleport yourself halfway into solid world geometry and be unable to do anything but \kill and respawn.

I'm looking at existing Q3 code for ways to do this, and nothing seems exactly suited for testing whether the player, or any entity for that matter, is intersecting with world geometry, other than a trace of course - and most of the approaches I can think that use trace would use lots of them (in different directions) in a single frame, which seems very inefficient.

I tried trap_EntitiesInBox, but that doesn't seem to catch the world entity, just things besides the player. I'm not sure I understand how trap_EntityContact works, might that be what I want? Or is the "trace in different directions from the player origin" approach viable? Thanks in advance for any advice.
corncobman
Posts: 304
Joined: Fri Aug 08, 2003 7:00 am

Re: Q3 engine: world encroachment checks?

Post by corncobman »

I remember doing this and running into the same problem.

I solved it by using a trap_trace() call from the players origin up to the player's height and if the trace.fraction is 1.0 (or 0 I can't remember what the exact value is for a solid object) then you don't do the teleport.
-It is not the fall that kills you. It's the sudden stop at the end. (Douglas Adams)-

[url=http://www.violationentertainment.com/misc/ccm]-An eyeful a day is bloody fantastic!-[/url]
JPL
Posts: 13
Joined: Sun Nov 11, 2007 1:17 am

Re: Q3 engine: world encroachment checks?

Post by JPL »

I solved it by using a trap_trace() call from the players origin up to the player's height and if the trace.fraction is 1.0 (or 0 I can't remember what the exact value is for a solid object) then you don't do the teleport.
That wouldn't cover the case where the warp location is really close to the ground, so the trace up from origin would be clear but the trace to the ground wouldn't be, and you'd be stuck halfway in the ground.

After some investigation, it looks like trap_EntitiesInBox and trap_EntityContact don't return the world entity even if it is encroaching, so I'll have to go with the trace approach. Now I just have to come up with some logic that gives the right balance of efficiency and robustness. I'll post here for future reference when I've got something workable.
JPL
Posts: 13
Joined: Sun Nov 11, 2007 1:17 am

Re: Q3 engine: world encroachment checks?

Post by JPL »

I've got a decent, though probably not ideal solution that goes something like this:

1. trace from the player's current location to the hit location, with the player's min and max points as the extents
2. if that original trace didn't hit anything, we have a totally clear path to the destination, so just do the warp. otherwise, iterate thusly to find a safe spot:
3. trace from the player's origin to the bottom of the player's bounding box. if it hits something, we're too close to the ground, so nudge the destination point up by mins[2] and try again
4. trace from the player's origin to the top of the player's bounding box. if it hits something, we're too close to the ceiling, so nudge DOWN and try again
5. if neither the floor or ceiling traces hit anything, step back towards by a set amount (16 units in this case) and try again
6. do the original, non-zero-extent (Unreal term) trace from step 1 again and see if we're clear
7. after a set amount of unsuccessful tries, give up and send a negative feedback event so the player knows what's happened

This solution is by no means very robust, and the number of traces it grinds through before giving up means it's not terribly efficient either. The up and down traces obviously only cover clearance in Z axis, so theoretically it's possible for a significant slice of the player's bounding box in the X or Y dimension to be stuck in world geometry. When testing this I could never get a "stuck in a wall and have to suicide" failure case though.

This may well be basic stuff to a seasoned gameplay programmer, but I'm posting this for anyone who's still learning stuff like me.

Anyone who's interested in my progress on the rest of the project can check here.
Locked