xbdev - software development
Sunday July 21, 2024
Home | Contact | Support | 3D File Formats The bits and bytes... | 3D File Formats The bits and bytes...

3D File Formats

The bits and bytes...


Quake 3 BSP [Dealing with Collision - Collision Reaction]

Author: bkenwright@xbdev.net


You can't just stop when you hit a wall.  And if you've ever played a game like halo or quake, you'll actually notice that you slide along the wall.  Which is what we are aiming for here.  We can do this by taking the wall normal (direction its facing), point of collision and our original direction to give the new sliding direction along the wall.  We also take into account the angle and speed that we slide into the wall so our new direction is proportional to our original speed.

When you have a collision and generate a new direction and position, we also need to check this new position again in our collision detection.  You could recursively check this new position to get the best new position, but we just check once, and if our new collision response value is no good, then we'll just no move to it and the play can wiggle around and face a new direction, where we can try again.

Sliding along wall (Perpendicular)

For this demo, I actually show the collision response using rays and little spheres.  So its easier to visualise and play with the code to see what's going on.  In the next demo we'll use our collision response value to actually slide the player along the wall and prevent them leaving the level.

Small detail you'll notice, and the reason we always have to check our new collision response value against a second collision.  Is that our wall normal isn't always the one we want or expect.

Download Source Code (323kb)

The previous demo shows how we deal with collisions, by showing the point of collision and the new position value.  It doesn't actually interfere with our current position and its new position.  Thats where the next part comes in. We now use the above information to create the working demo you can't escape from!

Download Source Code (324kb)


Can't escape from the level

Its not enough to actually be on the wall and slide along it.  We needed to expand the code so that it stays a certain radius from the wall.  Radius-Line Collision detection is used.

So the actual player doesn't get to close to the wall.  As if you do it using the line-collision, our actual player is on the wall when a collision occurs and the view of the wall up close isn't to good...blocky and pixelly.  This keeps our players first person view a certain distance from the walls.

So you can walk around the level and slide along the walls.  You won't get stuck if you just hit a wall slightly as you go round the corner, it will let you slide off it.

You have a fully functioning level - it still needs a bit more.  As the player might want to straft left or right...which we could add to the keys.  Lighting is another area we can improve upon.  Adding further lighting will make the different walls stand out more - making it more room like.





Advert (Support Website)

Copyright (c) 2002-2024 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.