Heightmap collision

How to make simple collision with heightmap?I’m trying to handle collisions with terrain adn player with such code:

          self.player.dummy.setZ(self.terrain.getElevation(self.player.dummy.getX()/self.terrain.getRoot().getSx(),self.player.dummy.getY()/self.terrain.getRoot().getSy())* self.terrain.getRoot().getSz()*3.5+0.1)
  

But my player doesn’t move correctly on terrain,it’s Z coordinate doesn’t correspond to it’s block of terrain…
So how better to make collisions with terrain?

Lol, okay, that code makes not much sense.
You need to keep in mind that getElevation provides and asks for values relative to the terrain geometry. So smartly use player.getX(terrain) since player.getX() * terrain.getSz() will only work if they share the same parent node.

… maybe I should add a function to automate this process or so.

my player and terrain share the same parent node - render.I’ve tried that code,but it gives bad result as previous.Could you write automatization function because i try to solve this problem during 3 months and i think stable and simple terrain collision is interesting and useful thing for many people on this forum.