Hello ! Im trying to implement a method that focused an object when I click on it. I create a raycaster that get the object of my click and then I try to target the position of the first element of my raycaster (the first element is always the nearest). But It doesnt work my camera still focus my character
focusedObject()
{
document.addEventListener('click', (event) => {
this.height = this.main.sizes.height
this.width = this.main.sizes.width
const focusCamera = new THREE.PerspectiveCamera( 45, this.width / this.height, 1, 1000 );
this.scene.add( focusCamera );
const mouse = new THREE.Vector2();
var x = event.clientX
var y = event.clientY
mouse.x = ( x / this.width ) * 2 - 1;
mouse.y = - ( y / this.height ) * 2 + 1;
this.raycaster.setFromCamera(mouse, this.camera.instance);
this.intersectsFocus = this.raycaster.intersectObjects(this.scene.children);
this.camera.controls.target.set(this.intersectsFocus[0].object.position.x,this.intersectsFocus[0].object.position.y,this.intersectsFocus[0].object.position.z)
})
I tried controls.target.set(…) and camera.lookAt(…) but no one works.
Thanks for helping