Three.js: Colliding the camera on the ground

How do I do add terrain camera collision in three.js.

The terrain is from the mrdoob three.js examples and is randomly generated and I am currently converting it to a heightmap.

I'm going to do the collision like this:

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

How should I do it?

+3


source to share


1 answer


The theory is that you send the beam from where you are (camera position) straight down. You will find the intersection point and based on the distance you decide what to do. Implementation wise I can't help you, but THREE. Ray has to help you.



+3


source







All Articles