How do I make the camera rotate around the clicked model?

How do I make the camera rotate around the clicked model?
The idea is to insert a pivot point into camera.setTarget (BABYLON.Vector3.Zero ()) after clicking on that model…
mesh.setPivotPoint(new BABYLON.Vector3(x, y, z));
Line 116;
Any idea?

You can just call camera.setTarget(bjsevt.source);

See line #103:

1 Like

Thank Deltakosh for your reply
This is great … is this possible without moving the camera? To move the camera manually by moving the mouse?

Aldin, if you want to ensure that your camera position remains same after setTarget, then temporary stow camera.position before setTarget… and then restore afterwards. Might work. Should work. :slight_smile:

        var oldpos = camera.position.clone();
        console.log("old pos:", oldpos);
        camera.setPosition(oldpos);  // perhaps ... camera.position = oldpos;
        console.log("after-setTarget camera pos:", camera.position);
        header.textContent =;

Something like that. :slight_smile:

1 Like

Perfect and understandable… :slight_smile:
But var oldpos = camera.position.clone (); still does not get the old position and is moving again…
Line 103;

Not sure to understand the problem as the position before and after seem identical to me:

1 Like

Yeah, those quick camera ROTATION changes… makes it APPEAR that the camera is changing position, but it isn’t. It is fooling Aldin. :slight_smile: (It fooled me, too, at first.) Part of the fun.

1 Like

Hey, what does the camera do to us? Bad camera :slight_smile:
Definitely visually it looks like the camera position changes with the target … By clicking on the model, it looks as the models move, how to remove that effect?
Perhaps the click pivot point model is moved to the center …
What I want to make is that the models do not move by clicking on them. There is an option in the blender to enable rotation around the selected model, but there is no effect on moving the model …
Here’s an example;

The models move because the camera rotates :slight_smile:
What you may want is perhaps moving the camera and the target so the image stays still?

I want the image to remain still as well as the last part of the video tutorials after turning on the blender option rotation around the selected model.

So you need to change both target and position (and do so math)

@aldin_abdagic Did you manage to get something working, am currently on the same issue, I re target onto a mesh but the camera moves and snaps into place, I want to stop the camera moving.

@Deltakosh could you point me in the right direction pls?

am trying to do this at the moment on a clicked mesh

export function targetMesh(scene, camera, previousTarget) {
//use scene picking ray to detect mesh for camera target
const ray = scene.createPickingRay(
const hit = scene.pickWithRay(ray);

let x = camera.position.x;
let y = camera.position.y;
let z = camera.position.z;

if (!hit.pickedMesh) {
return null;
} else {

camera.setPosition(new BABYLON.Vector3(camera._cache.position.x, camera._cache.position.y, camera._cache.position.z));


setTarget works correctly but it jumps to that point and i wanna remove that if i can

You could either create an animation to go there : Animations - Babylon.js Documentation

Or manually lerp to it (which is what the animation would do) Moving camera to an other position smoothly

1 Like