Game Development Community

Proper Implementation of Collision

by Nate "Nateholio" Watson · in General Discussion · 10/26/2007 (1:48 am) · 0 replies

This is just a cut/paste of a thread I have on another forum. Its concerning collision in an engine Im coding from scratch....

So Ive been putzing around with collision just for "fun".

The method Im using is to cast a ray from a number of units above the player (camera) to a number of units below them. The first object the ray hits is the Y-pos that the player will be placed. Its all fine and dandy for terrains, but obviously wont work for indoor portions of a map because the player will end up on top of them.

What is the "proper" method of doing collision checking for maps with both indoor and outdoor parts? Please forgive me, Im still pretty new to collision in a virtual world, even though I can implement it perfectly in real robots and such.


These are my thoughts on how its done, some parts of which I shouldnt even need to go over but I will anyway:


1) Objects have to be set up as collidable or not, and the ones that are need collision data. In my current setup, each collidable object has a "collision sphere" the radius of which is equal to half the object's longest dimension. There isnt really any sphere at all, just a radius value. Each object also has a collision box object that matches its maximum XYZ dimensions. Checking against this box is only done if another object enters the collision radius. I plan to use poly collision for objects that require it, and whose collision boxes fall partly within each other. This setup seems like it will allow fairly accurate collision without the burden of everything only using poly or box collision.

2) Collision tests should somehow be in the movement vector of the object (player). Im guessing I just cast a ray along the player's movement vector. This works fine if part of an object crosses the point the ray shoots through. The part I dont understand however, is how to efficiently check for things like stairs or the "cowboy walks into a bar and says ouch". It seems that Id need to do poly collision to allow the player through doors and the like (poly for the door at least, box for the player).

3) Im not too sure how to do collision once inside a structure. Its easy if there are no changes along the Y-axis, but I have stairs, ramps, etc. Do I just cast a ray down from "head to toe" and assume the player cant go over anything that is taller than a set height?


I know for a fact that Im not thinking out of the box on this stuff, and I would greatly appreciate input on how to implement decent collision without taking a dive on FPS. Please remember that Im new to the subject, though I do understand collision basics.