Can't rotate the cylinder horizontally

I use demo Babylon.js Playground
In this demo movement mouse left or right rotates the cylinder around its axis. Also movement up or down rotates the cylinder around other axis.

But i can’t rotate the cylinder like 2D clockwise and can’t rotate cylinder horizontally around its axis. How i have to change this demo to get this possibilities ?

Hello and welcome!

You need to apply rotation to your mesh.

    cylinder.rotation.x = BABYLON.Tools.ToRadians(90)
    cylinder.rotation.z = Math.PI/2

Example -
Axis rotation is measured in radians, but there is the built-in tool to convert degrees to radians (BABYLON.Tools.ToRadians(some degree)). One can use what is more convenient.

Also, the rotation itself is the Vector3 object, so it is possible to write like:

cylinder.rotation = new BABYLON.Vector3(Math.PI/2, 0, Math.PI/2)

Example -

Please note, that actually the mesh itself doesn’t rotate with mouse moves - it is the camera which rotates around the mesh. Here is the same example with Free camera - press arrow keys to see the difference:


Thanks for the detailed answer. You just saved me a lot of time!

1 Like