Let’s say I have two moving Object3Ds, source and target, and I want source to rotate towards target, in a fashion similar to lookAt. my function is:
const up = new THREE.Vector3(0, 1, 0); const p1 = source.getWorldPosition(new THREE.Vector3()); const p2 = target.getWorldPosition(new THREE.Vector3()); const vector_direction = new THREE.Vector3().subVectors(p2, p1).normalize(); const align_q = new THREE.Quaternion().setFromUnitVectors( up, vector_direction ); source.quaternion.copy(align_q);
it works more or less like lookAt, and similarly to lookAt, when the direction crosses north and south poles, the source object “spins” so it always faces up.
Now, is there any way to avoid this? I mean, given an initial object orientation, I’d simply like to rotate it towards the target, and if it crosses the poles, it lust keeps rotating and “facing upside down”.
How can I achieve this behaviour?
thanks in advance.