3

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?

DoctorAV
  • 1,189
  • 1
  • 14
  • 40
YUMatty
  • 73
  • 6

1 Answers1

3

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.

gaitat
  • 12,449
  • 4
  • 52
  • 76