Adding collision to a generated terrain

Hi guys.

I have created a terrain using the GeoMipTerrain class. Since there is no egg file, how can I add the collision detection similar to the Roaming Ralph example, so that my character walks correctly on the terrain.

I think in the RR example it’s the { Polyset keep descend } line in the egg file that does the trick, but since a generated terrain doesn’t have an egg file, I’m not sure how to approach this.

Thanks in advance.

It’s possible to enable collision geometry for the terrain, however, this is an extremely inefficient way of collision detection.
The correct way to do it is by polling getElevation with the player’s x and y relative to terrain as parameters, then multiply the result by the terrain scale and you’ll have the Z position of the terrain at that point.
This has been asked on the forums many times - search and you’ll find some sample code.

Yes, I have seen it, but the problem is my character won’t walk because it doesn’t recognize the “terrain” as an entery.

Ha. Your game is a Roaming Ralph clone? :wink:
RR works in such a way that he won’t move when no collision occurs. So you should just remove the code that puts ralph’s position back every frame.

You shouldn’t do collision with terrain, since it’s terribly slow and inefficient.
But if you insist, it’s really as easy as setting the into bitmask of the terrain. e.g. terrain.getRoot().setCollideMask(mask).

Thanks a lot.

P.S - I’m making a 3rd person Tom & Jerry like game with many power-ups and, but I am using RR-like controls (improved though) and camera.

pro-rsoft, you obviously have a lot on your plate, but have you considered adding efficient collision detection with GeoMipmap terrain? Your suggestion for querying height at points works for walking on terrain but would be inadequate for operations such as intersecting a projectile with terrain or performing advanced collision dynamics such as ODE collisions of shapes with terrain.

In theory it should be fairly simple to make fairly efficient collisions, at least for small “from” colliders: just find the AABB of the from object, determine the set of polys in the terrain which intersect the AABB (should be very fast), copy these polys into an array and collide the from object with these polys.

I haven’t looked at the GMMT code, but this seems straightforward and should produce very good speedup in most cases. I’ve used this technique on a terrain implementation similar to GMMT for a non-Panda3D game and it worked quite well.

I did consider it. I think I’m going to be adding a CollisionHeightfield solid sooner or later that does efficient collision detection, probably better than the approach you mentioned.
Don’t have time for it soon, though.

Oh, by the way. Note that a smaller block size results in more and smaller sub-nodes and thus more efficient collision detection.