Move to position

I have below PG

when I click on ground, camera should move to clicked position, which I am achieving with animation

var animateToPoint = function(start, finish) { 
    isAnimating = true;
    var end = finish.clone();
    var animating = BABYLON.Animation.CreateAndStartAnimation('cam', root, 'position', 120, 120, start, end, BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
    animating.onAnimationEnd = () => {
        isAnimating = false;
        impact.isVisible = false;

The issue is when clicked on ground, camera doesn’t move to the exact location where it is clicked, instead it moves camera to centre of clicked mesh position.
any help? Thanks

adding @Cedric

1 Like

let me check

1 Like


Isn’t it because you didn’t set the finish to the pickedpoint?

1 Like

thanks @Cedric
pickResult.pickedMesh.position and pickResult.pickedPoint provides same result, camera doesn’t move to exact location on ground where mouse was clicked.

What do you mean by ‘exact’ ? Is there a way to get the delta or the exact position and compare it?

here is a PG how I wants to move camera at clicked position

so basically what I did in above PG is added 5 to Z position to go at clicked point

var end = new BABYLON.Vector3(finish.position.x, finish.position.y, finish.position.z+5);

I think I understand. That’s because of your root transform. The camera position is relative to that root. so you need to set camera local position to 0 in order to get no difference with the root position.

sorry a bit confused, where would I set camera local position in above PG? something like camera.setTarget(root.position);?

line 3, new BABYLON.Vector3(0, 5, -10) that value will be relative to the root transform.

not sure if understood correctly, here I updated root position with camera,
root.position = new BABYLON.Vector3(0, 5, -10);
but it has same issue, doesn’t go to clicked position


then you can animate the camera directly

1 Like

Thank you :bowing_man:

1 Like