# Prevent Excessive Spinning When Animating ArcRotateCamera

**URL:** <https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031>\
**Category:** Questions\
**Tags:** arcrotatecamera\
**Created:** [August 5, 2023, 3:48pm UTC](https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031 "2023-08-05T15:48:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![djeustice](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/djeustice/32/5517_2.png) [@djeustice](https://forum.babylonjs.com/u/djeustice)\
**Post date:** [August 5, 2023, 3:48pm UTC](https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031/1 "2023-08-05T15:48:53Z")

</div>

Hello Everyone,

I have a scene that loads with an ArcRotateCamera that can only orbit or spin on the camera.alpha axis. I have a GUI elements in the scene, when the user clicks it, the camera animates to a profile view of the mesh in the scene. The issue I’m having is if the user orbits several times around the mesh and then clicks the button for the camera animation, the camera spins excessively during the animation, basically unwinding the orbits the user performed.

What is a proper solution to animate the camera smoothly from it’s current position to the end animation position? Some things I have tried are testing different ease functions, clamping the camera.alpha degrees to 360 in order to prevent heavy spinning, and changing the camera to a freeCamera when the GUI is clicked.

Here is a playground of my scene:

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

And here is the actual project I’m working on:  
[https://david-eustice.com/pilot\_plant/index.html](https://david-eustice.com/pilot_plant/index.html)

Thank you kindly, I appreciate your input.

-Dave E.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 6, 2023, 6:01pm UTC](https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031/2 "2023-08-06T18:01:32Z")

</div>

The animation seems ok to me.

The alpha value is animated from 3.101 to 6.297, so the camera is doing a half-turn around the mesh.

In your live link, you should check the “from” and “to” values you use for the animation, they may not be what you think they are.

---

<div class="post-metadata">

**Author:** ![djeustice](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/djeustice/32/5517_2.png) [@djeustice](https://forum.babylonjs.com/u/djeustice)\
**Post date:** [August 6, 2023, 8:05pm UTC](https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031/3 "2023-08-06T20:05:41Z")

</div>

If the user spins around the scene a lot (lets say 6 times) and then clicks the GUI bitton to play the animation, the camera.aplha will spin until it reaches the end animation camera.aplha value.  
Is there a better way to do this? I’d like it if the camera would go straight from it current position to the side profile view but I am not sure that’s possible with the arcRotateCamera. I was thinking if I could change the camera.aplha from radian to degrees and clamp the value so once it camera orbit completes 360 degrees, it starts over again at 0 degrees. This might at least minimize the spinning when the animation plays.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 6, 2023, 9:54pm UTC](https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031/4 "2023-08-06T21:54:07Z")

</div>

You should normalize the values between 0 and 2\*PI before doing the animation:

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

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [August 7, 2023, 8:14am UTC](https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031/5 "2023-08-07T08:14:49Z")

</div>

I also use what

> ```
> camera.alpha = camera.alpha % (Math.PI*2);
> if (camera.alpha < 0) camera.alpha += Math.PI*2;
> 
> ```

did to solve the same problem  
Like [Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)’s in PG code  
I haven’t found anything more elegant than this.

---

<div class="post-metadata">

**Author:** ![djeustice](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/djeustice/32/5517_2.png) [@djeustice](https://forum.babylonjs.com/u/djeustice)\
**Post date:** [August 7, 2023, 3:20pm UTC](https://forum.babylonjs.com/t/prevent-excessive-spinning-when-animating-arcrotatecamera/43031/6 "2023-08-07T15:20:34Z")

</div>

Thank you @Evgeni_Popov and @11128 this works beautifully.  
I appreciate you taking the time to help me with the solution.
