How to find direction be camera and position

Please do not forget to add a link to a Playground to get a faster answer:

Hi I want find direction be camera and position,

in screenshot when I click any where I want move camera to this position and direction write now I am able to switch camera position but I have issue in Direction

this.sceneObserver = scene.onPointerObservable.add((evt) => {
if (evt.type === BABYLON.PointerEventTypes.POINTERDOWN) {

var pickInfo: any = this.scene.pick(
this.scene.pointerX,
this.scene.pointerY,
data,
data,
this.cameraArc
);
var point = pickInfo.pickedPoint
this.camera.position = new Vector3(pickedPoint._x, pickedPoint._y, pickedPoint._z);
}
});

camera position change done issue in Direction.

From what I understand you want to move camera to picked point and look at direction relative from your previous camera position towards your picked point?

At first I would calculate direction/distance vector, then add to picked point and set as target of camera:

const direction = pickInfo.pickedPoint.subtract(camera.position)
const newTarget = pickInfo.pickedPoint.add(direction)
this.cameraArc.setTarget(newTarget) // or this.cameraArc.lockedTarget = newTarget
2 Likes