# Rotate the object towards the direction of the camera

**URL:** <https://discourse.threejs.org/t/rotate-the-object-towards-the-direction-of-the-camera/19869>\
**Category:** Questions\
**Tags:** quaternion, math\
**Created:** [October 17, 2020, 9:14am UTC](https://discourse.threejs.org/t/rotate-the-object-towards-the-direction-of-the-camera/19869 "2020-10-17T09:14:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxsl89](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/maxsl89/32/14038_2.png) [@maxsl89](https://discourse.threejs.org/u/maxsl89)\
**Post date:** [October 17, 2020, 9:14am UTC](https://discourse.threejs.org/t/rotate-the-object-towards-the-direction-of-the-camera/19869/1 "2020-10-17T09:14:26Z")

</div>

Hello dear community!  
I have been studying the docs and practicing for a week now and have a lot of fun with it!  
I have an object in the scene that is specified as a target for the camera

_**const controls = new OrbitControls(camera, renderer.domElement);**_

By pressing the keys, I move the object and the camera follows it perfectly  
I would like the object to be turned towards the direction of the camera.  
i tried to do so  
_ **modelMesh.rotation.y = camera.rotation.y;** _  
but in this case the object does not always turn in the right direction

help plz  
 ![photo_2020-10-17_13-12-08](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/d/d15ede077651bd7c72328e70770ad1a4dbe8f9ed.jpeg)

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [October 17, 2020, 10:10am UTC](https://discourse.threejs.org/t/rotate-the-object-towards-the-direction-of-the-camera/19869/2 "2020-10-17T10:10:37Z")

</div>

Please try it with the approach from this example:

> **[three.js webgl - math - orientation transform](https://threejs.org/examples/webgl_math_orientation_transform)**

The idea is to specify a target orientation and then use [Quaternion.rotateTowards()](https://threejs.org/docs/index.html#api/en/math/Quaternion.rotateTowards) to gradually rotate the object to its new focus point.

---

<div class="post-metadata">

**Author:** ![maxsl89](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/maxsl89/32/14038_2.png) [@maxsl89](https://discourse.threejs.org/u/maxsl89)\
**Post date:** [October 17, 2020, 10:46am UTC](https://discourse.threejs.org/t/rotate-the-object-towards-the-direction-of-the-camera/19869/3 "2020-10-17T10:46:23Z")

</div>

Thanks for the answer, thanks to you I figured out the rotation to the point

The object turns smoothly and nicely towards the camera thanks to this code,

```
targetQuaternion = camera.quaternion;
  if (!modelMesh.quaternion.equals(targetQuaternion)) {
    var step = rotationSpeed * delta;
    modelMesh.quaternion.rotateTowards(targetQuaternion, step);
  }

```

**but I need, in the opposite direction** , is there a way to invert?

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [October 17, 2020, 12:24pm UTC](https://discourse.threejs.org/t/rotate-the-object-towards-the-direction-of-the-camera/19869/4 "2020-10-17T12:24:04Z")

</div>

> [@maxsl89](#):
>
> **but I need, in the opposite direction** , is there a way to invert?

`rotateTowards()` always uses the shortest path to transform from a given orientation to a target one. It’s not possible to influence this process. TBH, I’m not sure how to implement what you are looking for.
