# lookAt - flip / spin looking at poles

**URL:** <https://discourse.threejs.org/t/lookat-flip-spin-looking-at-poles/52764>\
**Category:** Questions\
**Tags:** coordinate-system, transform, lookat\
**Created:** [June 13, 2023, 10:38am UTC](https://discourse.threejs.org/t/lookat-flip-spin-looking-at-poles/52764 "2023-06-13T10:38:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stmaccarelli](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/stmaccarelli/32/3181_2.png) [@stmaccarelli](https://discourse.threejs.org/u/stmaccarelli)\
**Post date:** [June 13, 2023, 10:38am UTC](https://discourse.threejs.org/t/lookat-flip-spin-looking-at-poles/52764/1 "2023-06-13T10:38:21Z")

</div>

Hello everyone.  
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:

```javascript
        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.

---

<div class="post-metadata">

**Author:** ![mjurczyk](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mjurczyk/32/10995_2.png) [@mjurczyk](https://discourse.threejs.org/u/mjurczyk)\
**Post date:** [June 13, 2023, 10:41am UTC](https://discourse.threejs.org/t/lookat-flip-spin-looking-at-poles/52764/2 "2023-06-13T10:41:35Z")

</div>

> [@stmaccarelli](#):
>
> How can I achieve this behaviour?

Maybe stupid question, but if you want it to work like lookAt, rotate like lookAt, face direction properly like lookAt … why not lookAt 👀?

---

<div class="post-metadata">

**Author:** ![stmaccarelli](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/stmaccarelli/32/3181_2.png) [@stmaccarelli](https://discourse.threejs.org/u/stmaccarelli)\
**Post date:** [June 13, 2023, 10:44am UTC](https://discourse.threejs.org/t/lookat-flip-spin-looking-at-poles/52764/3 "2023-06-13T10:44:51Z")

</div>

ahah, that’s right, but it doesn’t matter, the core of my function is more or less the same as lookAt, and the result is the same.  
Problem is with transformations, and I don’t know so much about them.
