# Scene rotation with strange behaviour

**URL:** <https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241>\
**Category:** Questions\
**Created:** [December 7, 2023, 8:27am UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241 "2023-12-07T08:27:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivier\_Andre](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/olivier_andre/32/36465_2.png) [@Olivier\_Andre](https://forum.babylonjs.com/u/Olivier_Andre)\
**Post date:** [December 7, 2023, 8:27am UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/1 "2023-12-07T08:27:50Z")

</div>

Hi all,  
I have a question regarding a strange behaviour of the result of the following:

// ----------------------------------------------  
speed=45;  
frameCount=200;  
focusX=myMesh.position.x;  
focusZ=myMesh.position.z;

cameraMove = function(cam, criteria, speed, frameCount, newPos) {  
ease = new BABYLON.CubicEase();  
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE\_EASEINOUT);  
go = BABYLON.Animation.CreateAndStartAnimation(‘deplacement’, cam, criteria, speed, frameCount, cam.position, newPos, 0, ease);  
go.disposeOnEnd = true;  
}

// ===========================  
// = Déplacement de la caméra =  
// ===========================  
cameraMove(camera, ‘position’, speed, frameCount, new BABYLON.Vector3(focusX, 20, focusZ-25));   
cameraMove(camera, ‘rotation’, speed, frameCount, new BABYLON.Vector3(focusX+25, 20, focusZ));

// ----------------------------------------------

The scene rotates and moves I don’t know how many times then stops at a position that has nothing to do with the position initially requested.

It’s quite difficult to put my program in the playground as I have more the 7300 meshes defined (locations in a warehouse) and my program uses Ajax functions to run Php programs.

Thanks for your help.

Olivier

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [December 7, 2023, 9:04am UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/2 "2023-12-07T09:04:09Z")

</div>

hi @Olivier_Andre welcome to the forum!

Whithout putting all your program into a PG, can you try to repro with default playground?

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [December 7, 2023, 9:53am UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/3 "2023-12-07T09:53:54Z")

</div>

Hello and welcome!  
I believe your problem is related with this PR - [https://github.com/BabylonJS/Babylon.js/pull/14584t](https://github.com/BabylonJS/Babylon.js/pull/14584t)  
You may try to use temporarily (until this PR will be merged etc) some earlier Babylon.js version.  
(Seems that the release is done already - [Release 6.33.0 · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/releases/tag/6.33.0))

Another way - change animation loop mode as described here - [Camera Animation bug - #6 by Juancode](https://forum.babylonjs.com/t/camera-animation-bug/46211/6)

Your old code:  
`BABYLON.Animation.CreateAndStartAnimation(‘deplacement’, cam, criteria, speed, frameCount, cam.position, newPos, 0, ease);`

New code which should work:  
`BABYLON.Animation.CreateAndStartAnimation(‘deplacement’, cam, criteria, speed, frameCount, cam.position, newPos, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT, ease);`

Hope it will help 🙂

---

<div class="post-metadata">

**Author:** ![Olivier\_Andre](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/olivier_andre/32/36465_2.png) [@Olivier\_Andre](https://forum.babylonjs.com/u/Olivier_Andre)\
**Post date:** [December 7, 2023, 10:27am UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/4 "2023-12-07T10:27:16Z")

</div>

Thanks for your answers.

@labris , I’ve tried with “ANIMATIONLOOPMODE\_CONSTANT” but same result.

@Cedric , you can see the problem here. Uncomment the block at the bottom of the page to see the issue.

In fact, I just want to focus the selected location.

Thanks to all.

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

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [December 7, 2023, 11:59am UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/5 "2023-12-07T11:59:09Z")

</div>

If I comment rotation line, animation works as it should.  
There is some problem with rotation in your code - check this modification: [https://playground.babylonjs.com/#G8EP7L#4](https://playground.babylonjs.com/#G8EP7L#4)  
(icamera rotation gives strange result even without animation).

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [December 7, 2023, 12:33pm UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/6 "2023-12-07T12:33:17Z")

</div>

cameraMove is animating always from the camera’s starting position instead of the camera’s starting rotation, are you sure this is what you intend?

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/7/5744b1a550c0d353d473f5a26a9c9fc61c0f81d4.png)

---

<div class="post-metadata">

**Author:** ![labris](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/labris/32/12576_2.png) [@labris](https://forum.babylonjs.com/u/labris)\
**Post date:** [December 7, 2023, 12:51pm UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/7 "2023-12-07T12:51:29Z")

</div>

Since the rotation is measured in radians, it rotates crazy with such high values like 20 etc.

---

<div class="post-metadata">

**Author:** ![Olivier\_Andre](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/olivier_andre/32/36465_2.png) [@Olivier\_Andre](https://forum.babylonjs.com/u/Olivier_Andre)\
**Post date:** [December 7, 2023, 12:58pm UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/8 "2023-12-07T12:58:30Z")

</div>

GREAT!!! It works.

Many thanks for your help.

Have a nice day.

Olivier

---

<div class="post-metadata">

**Author:** ![Olivier\_Andre](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/olivier_andre/32/36465_2.png) [@Olivier\_Andre](https://forum.babylonjs.com/u/Olivier_Andre)\
**Post date:** [December 7, 2023, 1:14pm UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/9 "2023-12-07T13:14:12Z")

</div>

☹

Just copy & paste error on the PG…

Sorry

---

<div class="post-metadata">

**Author:** ![Olivier\_Andre](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/olivier_andre/32/36465_2.png) [@Olivier\_Andre](https://forum.babylonjs.com/u/Olivier_Andre)\
**Post date:** [December 7, 2023, 1:16pm UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/10 "2023-12-07T13:16:41Z")

</div>

@carolhmj

I’m sorry, I’m new to BJS. Could you please give me the correct syntax to rotate the camera please?

Thanks.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [December 7, 2023, 1:24pm UTC](https://forum.babylonjs.com/t/scene-rotation-with-strange-behaviour/46241/11 "2023-12-07T13:24:00Z")

</div>

Pass the camera’s initial property along with the property you want to achieve at the end of the animation. Here’s an example in your code: [Strange behaviour | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#G8EP7L#6)
