Trying to create a threejs mesh that responds to mouse movement by moving from side to side, but encountering an issue when changing directions.
Below is the code snippet for the mousemove function:
The problem arises when switching directions after initial movement, causing the mesh to only start moving in the opposite direction once it nears the original x position of the mouse click.
let originx;
onDocumentClick(evt) {
originx = evt.pageX;
document.addEventListener('mousemove', onMouseMove);
}
onMouseMove(evt) {
let _newX = myMesh.position.x + (originx - evt.pageX);
myMesh.position.set(_newX, myMesh.position.y, myMesh.position.z);
}