Rotation of a mesh don't work

Hello,

i try to animate the rotation of a mesh. i just try (for testing in console) to rotate with .rotate.y but didn’t work same with rotation.y the only rotation working is .rotationQuaternion.y but it’s scaling up too, i’don’t know really why.
However, i make a function with the animation animateLeftCar and it didn’t work
(it’s seems pretty hard to animate a simple rotation in babylon :s )
The playground Babylon.js Playground

and the full project for model on github : https://github.com/Thomaseustache/jeux_voiture

Thank you for helping me

Unfortunately, for me, your playground is too complex to work through. Would you please simplify to just show the rotation issue. For example just load the car and try to rotate it.

It could be that the imported model has its rotationQuaternion already set which used to cause problems but I thought had been dealt with in BJS v4.0.0 onwards - perhaps you are using an earlier version? See warning

setting .rotationQuaternion.y is not changing the rotation about the y axis, quaternions are more complex.

A quaternion has the form a + x i + y j +z k and not all quaternions are rotation quaternions.

A rotation quaternion has to be a unit quaternion, so changing just the y component will produce a none unit vector and the resulting quaternion will produce scaling.

In this PG the top box has random unit quaternions applied and so just rotates, the lower box is just random quaternion not all are unit ones and so produce scaling as well

https://www.babylonjs-playground.com/#1ST43U#227

More on quaternions and at Quaternions and spatial rotation - Wikipedia

Ok, first i try to change to the current version (apparently not the same as you say) and i have an error now with the loader.js

image

i just try to import a object with :slight_smile:

BABYLON.SceneLoader.Load(“low_poly_car_2/”, “scene.gltf”, engine, function (newScene) {
// do something with the scene
});

I try everything with the current version and i can’t import a 3d object…

i have nothing else.

I juste need

script src=“babylon.js”>
script src=“babylon.loader.min.js”>

??

I load the car and rotate with :
carModel.rotate(BABYLON.Axis.Y, 2 * Math.PI/2, BABYLON.Space.LOCAL);

It’s working, but how to animate the rotation ?
I want a custom animation of the car when i go left or right (like a small rotation of the car without the wheels)

Can you repro your current state in the PG? It would be far easier to help instead of trying to guess what your code is

Now i have that :https://www.babylonjs-playground.com/#SDXGL0#1 and i can’t import anymore object :confused:

yeah :slight_smile: you cannot just your code :slight_smile:
You do not need to create or handle the engine, it is done by the playground (PG) already

you just need to create a createScene() function that will return a scene

here is a doc to load external assets: Using External Assets - Babylon.js Documentation

Ok thank you you know why i have this error in babylon.loader.min.js:1 ?

“TypeError: Cannot read property ‘asset’ of undefined”

can you make sure to use these versions:
https://doc.babylonjs.com/babylon101/how_to_get#preview-version

Oh! I found the problem !!
If we want to use .rotate we need to set rotationQuaternion = null

It’s working fine now :smiley:

THANK YOU

2 Likes