Get current rotation y axis in angles

How do I get my camera’s current rotation of y axis in angles? That is 90 degrees etc.
I am aware of using rotationQuaternion but how do I get the y angle from it? Kindly help
Also I get the error that “camera.rotate is not a function”.

https://www.babylonjs-playground.com/#HB4C01#375

“camera.rotate is not a function

You should ask yourself why :slight_smile:

I suggest you start by reading these docs:

Because it is used only for meshes. So then how do I rotate the camera?
I have read those links but I am still confused. I just want to rotate my camera to a certain angle with rotate function.

right, rotate function does not exist for camera

for a ArcrotateCamera you simply change camera.alpha or camera.beta

They are in radians so you need to convert your degree to radians first

Thank you. So basically camera.alpha.rotate(…) ?

Basically NO.

camera.alpha = BABYLON.Tools.ToRadians(90);
console.log(BABYLON.Tools.ToDegrees(camera.alpha))
3 Likes

Thanks @JohnK :slight_smile:

@Deltakosh and @Deltakosh thank you :slight_smile: I actually failed to understand why camera.rotation would not work. Now I get it that the “alpha” and “beta” properties need to be accessed.

I created animations for camera rotation and its given under here (if anyone needs it):

BABYLON.ArcRotateCamera.prototype.spinTo = function (whichprop, targetval, speed)
        {
            var ease = new BABYLON.CubicEase();
            ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
            BABYLON.Animation.CreateAndStartAnimation('at4', this, whichprop, speed, 120, this[whichprop], targetval, 0, ease);
        }

//To start the animation:
 camera.spinTo("alpha", BABYLON.Tools.ToRadians(60), 100);
 camera.spinTo("beta", BABYLON.Tools.ToRadians(90), 100);
1 Like