I am using ThreeJS and have the following code which should make a specific object move up when you hover over it, something like:
function onPointerMove(event) {
pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
var intersects = raycaster.intersectObject(scene, true);
if (intersects.length > 0) {
var object = intersects[0].object;
if (object == chair) { // Can I do this?
object.position.set(0,0,10)
}
}
}
window.addEventListener( 'pointermove', onPointerMove );
chair
is defined to be:
loader.load('assets/models/Chair.glb', (gltf) => {
scene.add(gltf.scene);
gltf.scene.traverse( function ( object ) {
if ( object.isMesh ) {
object.castShadow = true
object.recieveShadow = true;
};
} );
var chair = gltf;
},
Is there any way to achieve this? I’ve already tried object == chair
and object === chair
but both unfortunately don’t work.