I'm currently working on a Three.js project where I need to create a sphere that follows the mouse cursor, similar to the functionality demonstrated in this example. The code snippet responsible for handling the mouse movement is as follows:
function onMouseMove(event) {
// Update the mouse variable
event.preventDefault();
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
// Make the sphere follow the mouse
mouseMesh.position.set(event.clientX, event.clientY, 0);
};
I've included a link to a JSFiddle containing the complete code, but it seems that according to the DOM, the mouseMesh
object is undefined. Can anyone help me identify what might be causing this issue?
Thank you in advance for any assistance provided!