Camera rotation in certain degree

Hi all,

In the playground, I am at the corner of the ground, how can I set camera.rotation such that I am watching 30 degrees apart from the left edge?
https://playground.babylonjs.com/#YGHUGN#4

You can use the Z angle (roll)

https://playground.babylonjs.com/#YGHUGN#5

Edit: fixed PG link. Thanks @Faber

@Cedric I think you linked Kuangzheng_Xia’s original playground, not a modified one.

As he said though, the Z angle is what you are looking for, @Kuangzheng_Xia.

Here you have the playground with a view at 30 degrees (see line 17). I used a helper function defined at the very end to convert degrees to radians and the other way around, if you’re more comfortable with it.

The issue you will have is when you try to move the camera with the controls, it might seem really chaotic. That’s because for a FreeCamera, the controls are acting through the position (moving | left mouse button) and target (panning | right mouse button), so if the rotation property has been changed, the controls will act as if it hasn’t (I don’t know if it’s an expected behaviour).

In this other playground, I replace the FreeCamera with an ArcRotateCamera (please see documentation here) (see line 6). Now the controls are using alpha,beta and radius for camera positioning. That means you can add your 30 degree rotation, and after that use controls (if you like) just as you normally would.

Tell us if you found something helpful or if we misunderstood your problem. :slight_smile:

1 Like

Thank you for helping.

I didn’t explain my problem properly. At the start, the camera looks straight along the left edge. Then I want the camera to rotate right or drag right to look 30 degrees apart from the left edge.

It is like a person looks forward and then rotates right for 30 degrees without changing position. The following screenshot is what I expected.

you want 30deg edge with the lower corner at the same place? AFAIK, that’s not possible without changing camera position.

I think he wants a fixed camera (ArcRotateCamera with near null radius should do it), above the lower corner, looking forward, and then make the camera look on the right by 30deg. But I may be completely off. :stuck_out_tongue:

The person would be standing on the corner, right ?

Please take a look at this playground. Does it look anything close to what you want ?
(comment the lines 17-20 on and off)

2 Likes

Thank you.

The person is standing on the corner. This is something I expected.

May you use FreeCamera instead of ArcRotateCamera?

1 Like

No problem, you can use a FreeCamera. Then you’ll just have to play with camera.rotation.y since camera.alpha only exists on ArcRotateCamera.

Here is the same playground but with a free cam.

Glad I could help. :slight_smile:

2 Likes

Cheers bro.

This is what I expected!

1 Like