I was wondering if it exists a function in Babylon to create a new Vector3 with two position vectors as arguments.
For example if I click somewhere in the world I want to get back the position of my click and with the position of my active camera create a new directional Vector3 (from the camera position to the click position, get with pickedPoint) to use with cameraDirection.
window.addEventListener(“click”, function () {
// We try to pick an object
var pickResult = scene.pick(scene.pointerX, scene.pointerY);
console.log(pickResult);
//let vec3 = camera.getTarget().subtract(camera.position)
let vec3 = pickResult.pickedPoint.subtract(camera.position).normalize();
camera.cameraDirection = new BABYLON.Vector3(vec3.x, 0, vec3.z); // I want to avoid to move the Y axis
});
So what I needed was the normalize but I don’t understand what it’s doing.
So finally it doesn’t work because I just get a vector with magnitude 1 but what I want is just move the camera to the clicked position so the magnitude can change.