I create a sphere in Three.js, which should follow the mouse whenever it moves, as shown in this example . The function that handles mouse movement is as follows:
function onMouseMove(event) {
event.preventDefault();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
mouseMesh.position.set(event.clientX, event.clientY, 0);
};
I am attaching a JSFiddle with the full code inside it, where you can see that according to the DOM, is undefined. Do you have any idea what I'm doing wrong? mouseMesh
Thanks in advance for your answers!
d_z90 source
share