Ok, Im working off https://tympanus.net/codrops/2018/12/06/interactive-repulsion-effect-with-three-js/ and Three.js - Push away and then restore elements position on "mouse move"
trying to get objects positioned in 3d space to be repelled by the mouse. To do this, I need to get the direction of the mouse relative to the object on x, y, z axes and move the object in the OPPOSITE direction.
I'm using TweenMax, and can change an object's position like this
TweenMax.to(m.position, .2, { x: 0, y: 0, z: 0});
The Tympanus can get the distance between the mouse and the object using
const distance = (x1, y1, x2, y2) => {
return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2));
}
const distancexyz = (x1, y1, z1, x2, y2, z2) => {
return Math.sqrt(Math.pow((x1 - x2), 2) + Math.pow((y1 - y2), 2)+ Math.pow((z1 - z2), 2));
}
But currently the tutorial propels the objects always in the same direction, not repelling the objects like Three.js - Push away and then restore elements position on "mouse move".
How can I make the objects move in the opposite direction of the mouse, like the repulsion on all axes?
Minimal, verifiable example:
Object can be moved in A DIRECTION (I dont have mouse direction, thats what I need) using TweenMax:
TweenMax.to(m.position, duration, { x: change, y: change, z: change});