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.