Terrain following

could somebody explain the steps in terrain following

Terrain following is pretty simple in jme. Each position on the map contains a height to go along with it. To obtain the height offset of the terrain, all you have to do is this:

Vector3f playerPos = player.getLocalTranslation();
Vector3f offsets = playerPos.add(terrain.getLocalTranslation());
float height = terrain.getHeight(playerPos.x, playerPos.z);
playerPos.y = height + 25;

That 25 is needed so that the player's feet touch the floor, because the pivot in jme is always the centre.

Hope that helps!

oh! thought that only worked on height maps! thx!!

well, all terrian types generate an array of ints as the heights. This is passed to terrainblock/terrainPage.

Terrain page then smoothes these ints out and renders a nice terrain for you :). But doing getHeight() your getting the smoothed, thus, a very accurate representation of how hight the terrain is (in offset terms).


oh so this doesn’t apply to a .obj file

No, this doesn’t apply to it. Having said that…Cep21 did implement a TriMesh follower which does what you need to do. It was initially commited to CVS but because the getHeight(…) thing was available, he took it down.


That is the code that he did. That code is 8 months old now. Im not sure if there are certain modifications needed for it to comply with the latest jme…

Good luck!


tring to compile that old terrainFollower thing and it’s having trouble with com.jme.util.Mempool guess it’s not apart of the libary any advice? I don’t know know what Mempool did so i need help