Placing models randomly on uneven terrain

Hi all! I’m just getting started with Panda3D and I’m trying to modify the Roaming Ralph sample to randomly place 10 pandas in the world.

I can randomly place the pandas but they end up inside the terrain.

#Creates 10 Random Pandas with collision spheres
        self.panda = []
        self.pandaColNpa = []
        for i in range(10):
            self.panda.append( Actor("models/panda-model",
            self.panda[i].setPos(random.uniform(-40, 60), random.uniform(-100, 100), 0)

I’ve been looking for awhile now and I can’t seem to find a way to set the Z coordinate so that is attaches the node to the uneven terain.

Any help would be appreciated. Thanks!

Nevermind, just adding in self.environ.getPos() for teh Z coordinate has fixed the issue. I knew as soon as I posted on here I’d figure it out

Use a ray that starts 100 units above the terrain and points strait down for each object. Then move the object to the position where the ray collides with the terrain.

For a lot of objects this will be slow, but you only have to call it once at creation.

Cool, thanks for that. It looks cleaner that way.