Quake3World.com Forums
     Programming Discussion
        Q3 engine: world encroachment checks?


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Q3 engine: world encroachment checks?

Gibblet
Gibblet
Joined: 10 Nov 2007
Posts: 13
PostPosted: 06-02-2008 11:15 PM           Profile Send private message  E-mail  Edit post Reply with quote


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.




Top
                 

Gomu Gomu no.....
Gomu Gomu no.....
Joined: 07 Aug 2003
Posts: 1902
PostPosted: 06-03-2008 05:09 PM           Profile Send private message  E-mail  Edit post Reply with quote


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)-

-An eyeful a day is bloody fantastic!-


Top
                 

Gibblet
Gibblet
Joined: 10 Nov 2007
Posts: 13
PostPosted: 06-03-2008 11:33 PM           Profile Send private message  E-mail  Edit post Reply with quote


Quote:
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.




Top
                 

Gibblet
Gibblet
Joined: 10 Nov 2007
Posts: 13
PostPosted: 06-05-2008 10:37 PM           Profile Send private message  E-mail  Edit post Reply with quote


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.




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group