[SOLVED]getElevation problems.

Hi, I am trying to use getElevation method to avoid using a collision ray to determine the z position of a given model.
Right now I am using ralph model and a heightmap created by L3DT map generator.

I place the model in world using the following code:

        self.ralph = Actor("/usr/share/panda3d/samples/Roaming-Ralph/models/ralph",
                                 {"run":"/usr/share/panda3d/samples/Roaming-Ralph/models/ralph-run",
                                  "walk":"/usr/share/panda3d/samples/Roaming-Ralph/models/ralph-walk"})
        self.ralph.reparentTo(self.render)

        
        ralphModel = self.loader.loadModel("/usr/share/panda3d/samples/Roaming-Ralph/models/ralph")
        min, max = ralphModel.getTightBounds()        
        actorSize = max - min
        scale = 10
        self.zDiff = actorSize[2]*scale
        self.x = 200
        self.y = 400
        self.z = self.terrain.getElevation(self.x, self.y) + self.zDiff
        self.ralph.setPos(self.x, self.y, self.z)
        self.ralph.setScale(scale)        

then I update the position with:

        if(time.time() - self.lastTime):
            self.x += 1
            self.y += 1
            print self.terrain.getElevation(self.x, self.y)
            self.z = self.terrain.getElevation(self.x, self.y) + self.zDiff
            self.ralph.setPos(self.x, self.y, self.z)
            self.lastTime = time.time()
        self.camera.setPos(self.ralph.getPos() + (0, 50, 2000))
        self.camera.lookAt(self.ralph.getPos())
            
        return Task.cont 

The placement works somehow decently, not perfect.
When the model start moving, it gets real terrible, the model soon enters the terrain and after sometime it is completely inside the terrain.

Any things I might be missing?

Thanks in advance.

This may be because of LOD. You can control this, just see http://www.panda3d.org/manual/index.php/Geometrical_MipMapping. Also you must mul getElevation by scale Z, not to add it.

I will try when I get at home.
Still, didn’t get the scale part.
This scale is applied only to the actor, why should I multiply to with the terrain z?

Solved…
Will leave this info so I can help those who get here…
The setTrueForce was set to True, so i could not be the LOD.
Double checking the info on MipMaping I found you should use this command:

        self.root = self.terrain.getRoot()
        self.root.setSz(100)

Then, in the reference you can find the entry:

Fetches the elevation at (x, y), where the input coordinate is specified in pixels.

This ignores the current LOD level and instead provides an accurate number. Linear blending is used for non-integral coordinates. Terrain scale is NOT taken into account! To get accurate normals, please multiply this with the terrain Z scale!

trueElev = terr.get_elevation(x,y) * terr.get_sz();

Which is wrong, since the right method is getSz() and you should use it in the root not in the GeoMipTerrain.

Well that is thanks to all those who used their time to read this.

PS: the final movement code is:

    def moveRalph(self, task):
        if(time.time() - self.lastTime):
            self.x += 0.01
            self.y += 0.01
            self.z = self.terrain.getElevation(self.x, self.y) * self.root.getSz() + self.zDiff
            self.ralph.setPos(self.x, self.y, self.z)
            self.lastTime = time.time()
        self.camera.setPos(self.ralph.getPos() + (0, 50, 10))
        self.camera.lookAt(self.ralph.getPos())
            
        return Task.cont 

Where self.zDiff is the adjustment done due to the model size.

i know this is solved and all, but how do i fix the fact that my character keeps either floating above the ground, or being up to his waist in it?