Collision, keeping the feet on the ground

Started by
9 comments, last by Tispe 10 years, 10 months ago

Hi, I am wondering what methods could be used to keep my characters feet on the ground.

I only have one vertex buffer and one index buffer that stores the Area mesh. How would I go about keeping my characters feet on the ground?

I was thinking about raycasting downward from the character position and set the correct height, but that means I have to traverse all the triangles in the area for all the characters. I could store two copies of the area, one in system memory and one in device memory and use the first for rendering and the latter for raycasting.

I could also further divide the Area into sections and check which sections the character is in and only traverse those triangles during the ray casting. But then I have to think about optimizing how many sections, sub-sections and subsub-sections I need.

Am I thinking straight or is there a miracle simple and easy cure to this (i.e creating heigt map from the buffers, but this would comprimise accuracy right)?

Advertisement

Hey, you use a bounding volume which is fit around your mesh, which is typically a cylinder or box for a character (though it can be other shapes if more appropriate). While you calculate the bounds once from your mesh (typically as a pre-process). Then you just match the bottom of your bounding object to the surface.

Using a proper physics engine, you would use the bounding object as the physical representation and let physics (ie. gravity) keep the object on the surface.

n!

Can you give me more details on how this bounding box is matched to the Area mesh?

Can you give me more details on how this bounding box is matched to the Area mesh?

Using standard run-of-the-mill collision. You could use a cylinder bounding volume for your characters, and divide up the polygons of your mesh into overlapping areas, and perform a cylinder/mesh intersection test (which breaks down into multiple cylinder/triangle intersection tests).

I don't follow. The character cylinder bounding volume is made up of vertices, which is checked against the Area vertex buffer, what is the algorithm here?

Hey, either I am not understanding what your issue is or I've not explained what I meant very well.

The character cylinder bounding volume is made up of vertices

A bounding volume does not have any verices, it is a parametric representation of your object. For example a cylinder will have a radius and a height, or a box would simply have width, height and depth. Where the parametric representation surrounds your object. A cylinder may be chosen over a box in some titles, as it simplifies the handling of colliding with corners. However, in the case of simply object to ground there isn't too much difference.

n!

You want to have separate representations for the graphical and the physical terrain (GPU and CPU), which for now can be the same mesh but later you might want to simplify the terrain to speed up physics or something.

Then, you can either:

-Use the raycasting method you described (represent your character as a point x units above the ground)

-Use some bounding volume (sphere, cube, cylinder, capsule...) which stays as close to the ground as possible without intersecting the terrain.

-Make a heightmap (and use raycasting on that, which would be a lot simpler than on an arbitrary mesh, as long as you raycast directly down)

All but the heightmap method (assuming you are able to make such a heightmap somehow) are probably easier if you use external libs to do it for you (for example just throw the terrain at a physics engine along with some shape representing your character which you use some fancy kinematic controller for)

If you use a physics engine, it will allow you to add other physical objects later so that might be a good choice.

o3o

I don't use any library DirectX9. So I need to write my own collision code. The height map I think will be inaccurate and does not support overlapping terrain.

Is there any tutorials on this bounding volume collision algorithm that you would recomend?

You can google for bounding volume collision detection, every collision/physics library uses it and it's extremely well documented on the internet.

n!

you can also use octree to improve performance if area is mostly static. you can also use heightmaps instead of ray cast.

This topic is closed to new replies.

Advertisement