I am trying to limit the camera position movements to specific areas defined by a 3D object/objects children. For example, if I had a walkway object on the ocean and I only wanted my user to be able to move the camera forward and backward on that walkway. Similar to a first person controller navigation mesh in Unity but without the AI aspects.
I would enjoy an AFrame based solution, but I do not mind writing a custom component if there is a THREE js solution.
Thank you!
you can create a THREE.Box3 to get the boundaries of the 3D object/objects children by:
var box = new THREE.Box3();
box.setFromObject(yourObject);
Inside the first person controller you can check if the camera is out of bounds:
if(camera.position.x > box.max.x){
camera.position.x = box.max.x;
}
if(camera.position.x < box.min.x){
camera.position.x = box.max.x;
}
if(camera.position.z > box.max.z){
camera.position.z = box.max.z;
}
if(camera.position.z < box.min.z){
camera.position.z = box.max.z;
}
I hope it will be helpful
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With