I would like to know how I could make the camera in this three js example: http://threejs.org/examples/#webgl_terrain_dynamic
follows the terrain's height. So, while the terrain is moving, the camera will go up and down according to the hills (height) of the terrain.
In other words, how I could get the terrain's height, knowing that the height of the terrain is built by an heightmap ?
I've already try with a Raycaster as follow:
var raycaster = new THREE.Raycaster( camera.position, new THREE.Vector3(0, -1, 0) );
var intersects = raycaster.intersectObject( terrain, false );
var intersect_point = intersetcs[0].point;
But intersect_point
always has its y value equal to 0 no matter where the camera is located.
Indeed, the height of the terrain in this example is created by an heightmap. Thus, the geometry of the terrain which is a plan is not changed by the heightmap and remains flat, hence the result of the raycaster.
Could you help me on how to find a way to get the terrain's height for a given position.
thanks a lot for your help.