Public Group

# Terrain Collision and Bounding spheres?u

This topic is 2183 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey Gamedev

I will shortly be making up some terrain for my game. How I do this, I'm yet to decide between a static mesh, or a heightmap.

I have 2 questions;

First of all, what is the best/the simplest/easiest/whatever gets the job done/ way to detect collision between the character, and the terrain. I don't want the player "snapped" onto the terrain, so I don't want him to glide up massive slopes. How would I go about doing this? Detecting the collision and offsetting the characters y position accordingly?

My second question is, I constantly hear people using bounding spheres for player collision. Why is this? It seems to me that a bounding box or cylinder would be more accurate (unless the player was a fatty) why use a sphere?

##### Share on other sites

sphere collisions are basically a matter of calculating distance between 2 points and subtracting 2 radiuses

it's a trivial and fast algorithm with sometimes acceptable drawbacks, unless your needs are specific

##### Share on other sites

sphere collisions are basically a matter of calculating distance between 2 points and subtracting 2 radiuses

it's a trivial and fast algorithm with sometimes acceptable drawbacks, unless your needs are specific

Yeah, I know how to do bounding sphere collision detection, sorry if my question wasn't worded right. I was just wondering why this may be preferrable to a bounding box or cylinder which could be closer to the size of the player then a sphere

##### Share on other sites

I was just wondering why this may be preferrable to a bounding box or cylinder which could be closer to the size of the player then a sphere

A sphere has the advantage to slide better over small obstacles and steps, whereas a cylinder or box will get stuck more easily. An often used alternative to a pure sphere is a capsule which have the benefit of being a better approximation of a humanoid and still have the sliding advantage of a sphere.

I'm yet to decide between a static mesh, or a heightmap.

In a simplest case a static mesh is more easily done, whereas a heightmap is often converted into a static mesh (sometimes on-the-fly to save some memory). Nevertheless, every modern physics engine, and I recommend to use one (building a physics engine can be extremly frustrating !), can handle tri-meshes and heighmaps.

##### Share on other sites

Thinking of the games I have coded as a hobbist, I have always handled this problem in two parts: first a way to keep the character on the ground and other that will avoid collisions with the world.

In my experience engines that support a height map can give you the height of a certein coordinate, so you wouldn't need any colision solid to know where the ground is. For static meshes I have always used a collision ray. An important side note: no matter which solution you choose, you must always check the angle between the point the character is and the one he is trying to move, this will avoid movement in very steep slopes (if the is trying to move from a lower to a higher point) and may trigger some short of fall (if the is trying to move from a higher point to a lower one).

To deal with the world collision I would use spheres rather than bounding box, since spheres are faster and more precise. If you have the option, you should use a capsule object (that is basically two spheres and a cilinder). I am assuming you are talking about the solid you will use on the characters, for objects I use whatever fits better (I try to go with spheres, but whan an object fits nearly perfectly inside a box, I use a box).

To sum things up, I would choose: Heigtmaps and capsules for collision. Finally, be sure to check Bullet library, that implements collisions in a simple and fast way (link: http://bulletphysics.org/wordpress/ )

Edited by KnolanCross

• 21
• 12
• 9
• 17
• 13