Reset camera position

I’m using UniversalCamera and ArcRotateCamera, we can switch camera by using universal camera checkbox. All i wanted to take the camera at front side of main mesh where i can view the whole mesh (no need to zoom out). It is not working as i expected. I tried to get the main mesh bounding info and take vectors of that mesh and add some number in z , it is taking camera to front position but cannot see whole mesh. For UniversalCamera same issue but also if camera faced to other direction it is not faced to mesh direction after clicking reset camera button.

Please help.

Hey @imarabinda,
I’m not sure but isn’t that similar issue to this one:

?
Maybe you can find some help there :slight_smile:

camera.ZoomOn() is only works with ArcRotateCamera, For UniversalCamera/FreeCamera it does not work i guess, I tried that for ArcRotateCamera is working, For both camera to work as same that’s why i was calculating the mesh front position.

Could try copying the code from createDefaultCamera to get the target/position/radius values but change it to use your animating function instead of setting the values right away.

1 Like

This helped me but still i’m having issue with the UniversalCamera, if it is moved to other direction (rotation), on clicking reset camera does not keep the face to the front of mesh. https://playground.babylonjs.com/#S0KJUA#28 , could you please help me on this? if we can get the rotation x,y position it can be fixed i guess. By the way thanks alot :heart_eyes:

Okay so I just changed it to animate the whole target as a Vector3 instead of animating each of the target’s properties separately and that helped. This way the target’s setter calls setTarget, rather than just changing the x, y, z values of the target. :slight_smile:

2 Likes

really appreciate your efforts, Thanks alot. :face_holding_back_tears:

1 Like