Basic Collision-Detection Demo
The CollisionTest demo, included with the source code for the tutorial, demonstrates the collision detection so far. It's the same demo as the BSPMapTest from the previous chapter, except that it adds collision detection and uses the GridGameObjectManager. In this demo, you are stopped when you run against a wall and you can go up stairs to higher platforms. You are also stopped when you run into an object, such as a robot or a crate. The projectiles you fire destroy the robots, and, just for fun, the projectiles stick to the walls, floors, ceilings, and other objects instead of passing through them. Collision detection in this demo works great, but it needs some serious help.
- You get "stuck" when you collide with a wall. In any 3D first- or third-person game, this can be very distracting to the player who expects to "slide" against a wall, especially when moving tightly around corners.
- Movement up and down stairs feels jerky because you are instantly moved up or down instead of scooting smoothly upstairs or allowing gravity to smoothly bring you down.
- You can't step over small objects in the way. Try shooting a projectile on the floor and stepping over it—you can't.
- You can't jump. Not that it's a part of collision detection—I'm just saying that you can't do it.
But, hey, good collision handling is a goal of this chapter, so let's fix those problems! And even though it's not really a collision-handling issue, this will be a good time to implement jumping as well because you can detect when an object is hitting something, even in midair.