Scene rotation with strange behaviour

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

hi @Olivier_Andre welcome to the forum!

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

Hello and welcome!
I believe your problem is related with this PR - 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)

Another way - change animation loop mode as described here - Camera Animation bug - #6 by Juancode

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 :slight_smile:

1 Like

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.

1 Like

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
(icamera rotation gives strange result even without animation).

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?

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

GREAT!!! It works.

Many thanks for your help.

Have a nice day.

Olivier

1 Like

:frowning:

Just copy & paste error on the PG…

Sorry

@carolhmj

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

Thanks.

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)

1 Like