# rotateAround and get back to initial position

**URL:** <https://forum.babylonjs.com/t/rotatearound-and-get-back-to-initial-position/26267>\
**Category:** Questions\
**Tags:** animation, mesh\
**Created:** [December 23, 2021, 9:37pm UTC](https://forum.babylonjs.com/t/rotatearound-and-get-back-to-initial-position/26267 "2021-12-23T21:37:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)\
**Post date:** [December 23, 2021, 9:37pm UTC](https://forum.babylonjs.com/t/rotatearound-and-get-back-to-initial-position/26267/1 "2021-12-23T21:37:46Z")

</div>

How can we rotate a mesh around a position, increment and decrement the rotate speed and get back to its initial position?

> **[Babylon.js Playground](https://playground.babylonjs.com/#L895WM%234)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

```auto
box.registerAfterRender((e) => {
    box.rotateAround(BABYLON.Vector3.Zero(), axis, speed);

    if (forward && speed < 1) {
        speed += step;
    } else if (speed > 0) {
        forward = false;
        speed -= step;
    }
});

```

Initial position:  
 ![Screenshot from 2021-12-23 21-27-17](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/7/1/71ad4bff31236444343df3a692dbc42eaab3f752.png)

Final position (Wrong):  
 ![Screenshot from 2021-12-23 21-27-00](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/4/f/4f40c2ca266aaca3133e7d15184acf849ee8b849.png)

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [December 23, 2021, 11:22pm UTC](https://forum.babylonjs.com/t/rotatearound-and-get-back-to-initial-position/26267/2 "2021-12-23T23:22:14Z")

</div>

You should check the rotation instead of the speed to be sure of where the box is ?

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [December 23, 2021, 11:38pm UTC](https://forum.babylonjs.com/t/rotatearound-and-get-back-to-initial-position/26267/3 "2021-12-23T23:38:24Z")

</div>

An easier way IMO is to set the mesh’s pivot point to the point that you want to rotate around and then use the createAndStartAnimation helper to simply animate rotation.x from 0 to numRotations \* TwoPi, with ease in and ease out. Below for example you can adjust the value 40 to adjust the speed and change the value 5 to however many full 360 degree rotations you want. 🙂 🍻

> **[Babylon.js Playground](https://playground.babylonjs.com/#L895WM%237)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)\
**Post date:** [December 24, 2021, 2:36pm UTC](https://forum.babylonjs.com/t/rotatearound-and-get-back-to-initial-position/26267/4 "2021-12-24T14:36:12Z")

</div>

Thanks @Blake this is exactly what I want 😁  
Based on your description and code, I did a function to set rotation animation to any mesh around a Point:

> **[Babylon.js Playground](https://playground.babylonjs.com/#L895WM%238)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

🎅 MERRY CHRISTMAS TO YOU ALL! 🎄

---

<div class="post-metadata">

**Author:** ![Treedbox](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/treedbox/32/20615_2.png) [@Treedbox](https://forum.babylonjs.com/u/Treedbox)\
**Post date:** [December 24, 2021, 2:49pm UTC](https://forum.babylonjs.com/t/rotatearound-and-get-back-to-initial-position/26267/5 "2021-12-24T14:49:21Z")

</div>

Yeah, I realize later that where I treat as “speed” was the angle, and that the `rotateAround` is cumulative, so, off course, values like 1 and 0 are not compatible with the final angle.  
Many thanks! 🙂
