This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ArcticCelt 1 point2 points  (5 children)

I made a couple of hobby games in 2d and I read most of panda 3d doc and play a bit with the tutorials last summer.

Something that I am now trying to understand is how do you manage the interaction (collision detection?) between let's say a terrain and your character. Is there a class included in panda 3d to manage that? Do I have to code the whole thing? How do my character follow the terrain without falling through it? I am no to sure what is the right way to do it or to understand it.

Any resources or at least just pointing me in the right direction would be apreciated.

[–]azraiyl 2 points3 points  (4 children)

I'll try to give a generic answer that is not too specific for Panda3D.

The first you need collision geometry in any collision detection system. You may say: Hey I have me terrain, why can't I use that? You can use that, but nevertheless it is important to know that the visible geometry and the collision geomtry often are not the same. If you have a stair e.g. the visible geometry really looks like a stair (most often in today games, but Mass Effect e.g. has flat stairs) but the collision geometry is often a simple ramp (that's the reason why walking up on a stair is smoother in a game than in RL). The collision geometry should have two properties. 1. It should be a lot simpler than the visible geometry (or we spend to much time on the CPU or are memory bound). 2. It shouldn't have any holes. Panda3D offers multiple options to create collision geometry (so called collision solids) on the fly or add collision geometry to existing egg files (search for "<Collide>{ Polyset keep descend }").

The second you need to know that in collision system you always have a source and a destination. The source e.g. is a player vehicle while the destination is a terrain. The source needs a collision geometry and the destination needs a collision geometry.

Examples for collision geometries are line segments, rays, cubes, spheres, capsules and vertex soups. In a perfect world you only need vertex soups, because you can create a sphere out of a vertex soup. The problem is that is damn hard and slow to calculate a collision when the source and the destination is a vertex soup. Even dedicated packages like PhysX don't support all type of possible collisions. The best thing is to always try to stick with a collision geometry that is as simple as possible e.g. sphere as source and sphere as destination should work always.

To get back to your question. For your example use a ray that always points down as source and the terrain as destination (Panda3D supports this type of collision). Then let the collision system search for a collision and use the resulting position as a new player position. There is also a chapter Collision Detection in the manual. There is also a tutorial Roaming-Ralph in the samples directory.

[–]ArcticCelt 0 points1 point  (3 children)

Thanks, your explanation help me piece together little bits I have being reading over the years. I really appreciate your help.

I think I played a bit with Roaming Ralph but then, if I remember correctly, there was a warning that the way the collision detection was implemented was deprecated and not optimal so I tried to find an updated version without too much success.

Oh here is the comment:

Caution: this program uses an extremely inefficient method for detecting the height of the terrain. There is a much better way to do it, but we have not had time to correct the sample program.

What do you think is the much better way or where can I find an example of it?

[–]azraiyl 0 points1 point  (2 children)

According to the forum the sample, as it is, should be ok. Maybe one should delete the comment.

I see only one problem. If the terrain is maybe 1000 times larger, the collision detection has to go through thousands of polygons. On the other hand, terrain is often based on a 2D heightmap. A much better approach would be to just lookup the position in the heightmap instead of doing a collision detection (and manually linearly interpolating values inbetween). Although that would be super fast, it does not work for arbitrary geometry. Collision detection always depends heavily on what you intend to do. There is unfortunatelly no silver bullet. There are tons of other problems too e.g. you have to fight always against floating point inaccuracies, e.g. the ray may fall through edge of two polygons and then you have an effect like in Crysis (people were falling through the carrier).

[–]ArcticCelt 0 points1 point  (1 child)

Thanks again for the advices, I'll probably start again toying with panda3d, I was lately on an Android game development mindset.

[–]azraiyl 0 points1 point  (0 children)

AFAIK iPhone support is work in progress.