I am eager to learn how to make the camera in a three js example follow the height of the terrain. Specifically, I want the camera to move up and down according to the hills and valleys of the terrain as it moves.
Essentially, I am looking for a way to obtain the terrain's height, considering that it is constructed using an heightmap.
My initial attempt involved using a Raycaster:
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;
However, the value of intersect_point
did not change according to the camera's position, as the terrain's geometry remains flat due to the use of an heightmap.
If you have any suggestions on a different approach to determine the terrain's height based on a given position, I would greatly appreciate your guidance.
Thank you for your assistance.