EasyGame Lesson12 – Collision Detection
This samples shows us several solutions about collision detection and collision detected handling without using some advance physics libraries.
Character Movement: every time you move the character into next position, you could check the next position is valid or not. If it was OK, then move the character ahead. Otherwise, you should try some different directions along the move direction , such as freeze the X, Y or Z axis then try again. If you still could not find any valid position, so could simply stay on the current position without moving.
Bullet Movement: Some game entities like bullet that moving with high speed. You could not simply check the next position is valid or not, because bullet will go though some items, like walls. One way you could do is using ray cast method to find whether some objects block my may with some distance. This is just the sample did. The other method is separating the bullet moving distance into a lots of smaller distance slice. The smaller the better. A simple bounds intersect check used for whether the bullet hit some objects or not. Some physics libraries use time slices to gain better realistic physics effect.
The full source code could be found from here.