What am working on nowdayz

Nowadays am working on implementing a Collision Detection System in my game engine (Just Another Game Engine).

I have written collision code multiple times while working on different games and each time i made it from scratch. Those systems were designed for specific primitives e.g. rectangle, circle, cube, sphere etc for specific games. So before this system i do had collision in my engine but it was for specific purposes for games it was made. and those special cases aren’t the ideal way to do collision detection in 3d environments.

So for 3D i mainly had collision detection for height-map terrains and some pillar (or cylindrical objects) placed on terrains. And that system assumed everything is aligned to xyz axes and gravity is along -y direction. So i can have a character as AABB or cylinder walking on terrain and colliding with cylindrical objects (with height along y).

For making the character walk on terrain i was just fetching the height (y value) of terrain at particular position (x and z) from height-map using this simple algorithm –

  • Get Player World Position
  •  Use x and z value to get the cell C in which player is
  • Get height value from height-map at four vertices making up that cell
  •  Interpolate the values on x-z plane to get height on that point
  • Scale the value with height-map scale factor
  • Assign the value to Y of player position

If you want a detailed example of how to make and render terrains based on height maps with code check these links : –

This is the most simple and useful method to make a character walk on terrain. In most of testing and maybe in some game/apps it can be a easy and quick way to do collision detection. We can even replace terrain by plane by making the function that returns height-map pixel value to return height of plane.

Also there are some issues related with this algorithm that can’t be avoided as shown in screenshots below : –

(notice that player object is walking up an almost vertical clip. Also its somewhat inserted into the heightmap)

Also using this algorithm ignores the slopes , walls ,etc and player we continue the hills , walks etc like spider man.

For intersection of player with pillars i was using collisions between cylinders aligned along y-axis. Here is the algorithm i was using –

  • Given 2 cylinders A & B . Check y value of both start and end position of A if any of them lies inside B end points.
  • Check same for B
  •  If any of above test return true just check the collision between 2 circles along xz plane

Again, an easy and quick way to do collision with any object that can be imagined as cylinder. But this algorithm assumes cylinders are aligned along y axes. And we often need more precise collision detection than with cylindrical bounding volumes.

Of course these algorithms can be improved to give better results in more generic cases but considering the amount of work involved and couple of more things that i wanted to do (I will discuss it in detail in next post), I thought it would be better to implement the proper collision detection system as it’s done in commercial game engines .

(In my next post in couple of days i will be posting more details on what i wanted to do and the progress of collision detection system. )

About chetanjags

Game Developer

Posted on March 27, 2012, in Game Development, JustAnotherGameEngine. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: