Hi there
I have this code that animate camera position when i click on the GLTF model on the scene
if (intersects.length > 0) {
if (INTERSECTED != intersects[0].object) {
var position = new THREE.Vector3();
intersects[0].object.getWorldPosition(position);
INTERSECTED = intersects[0].object;
gsap.to(camera.position, {
duration: 2,
x: position.x,
y: position.y + 1,
z: position.z + 7,
ease: "power4.out",
onUpdate: function () {
controls.enabled = false;
},
});
}
and i have this code for animate camera position with move mouse in the animate function
//----- tick function
object.rotation.y -= (mouse.x * 8 - camera.rotation.y) * timeSpeed;
object.rotation.x -= (-(mouse.y * 2) - camera.rotation.x) * timeSpeed;
if (object.rotation.x < -0.27) object.rotation.x = -0.27;
else if (object.rotation.x > 1) object.rotation.x = 1;
When I use without mouse move everything works correctly
But when I use mouse movement to rotate the camera on the move (tick) function, every time I click on the model, my camera does not move to the same place as before.
I mean, when I just use the click function, the camera pans to the front of the model
But when I use the mousemove function at the same time as the click function, the camera does not face the model
What is the problem?