Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js: Camera Collision on Terrain

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?

like image 222
YUMatty Avatar asked May 05 '26 19:05

YUMatty


1 Answers

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.

like image 104
gaitat Avatar answered May 10 '26 01:05

gaitat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!