Rotate camera towards an object

Hello,

How do I make my camera rotate towards an object with a certain x and z distance. I am not looking to do any animations. Just a quick method to achieve this. Any ideas?

Ideas? Sure;) What type of cam is it? The solution will also depend on the type of camera and whether you want a transition or not?

yes its actually ArcRotateCamera() :slight_smile:

Right. That should be quite easy:

To set your new target, use:

    camera.setTarget(scene.getMeshByID("myObj"));
    camera.target = new BABYLON.Vector3(0,0,0);

To set the distance from the camera (here we do not speak about x and z, since it doesn’t work this way with an arc rotate camera). You will want to change the upper limit of the camera for alpha, beta and radius, like this:

camera.upperRadiusLimit = 10;

You can also reposition your camera. If so, Do it BEFORE setting the new target:

camera.setPosition(new BABYLON.Vector3(-10, 10, 10));

EDIT: Forgot to mention, before you ask;)
If you don’t want the transition, but move straight to your next view, you can simply detach the camera, perform the above, and next reattach the cam.

2 Likes

Perfect thank you :slight_smile: