3
votes

How should I go about adding camera collision to a terrain in three.js.

The terrain is from 'mrdoob's three.js' examples and is randomly generated and I am currently converting it to height map.

I am thinking of implementing the collision as follows:

  • Create a 'box' object around the camera
  • If the box object is not touching the terrain, move the camera down.
  • If the box object IS touching the terrain, keep the Y axis of the camera.

How should I go about doing this?

1

1 Answers

3
votes

The theory is that you send a ray from the location you are (camera position) straight down. You find the intersection point and based on the distance you decide what to do. Implementation wise I cannot help you but THREE.Ray should help you.