I am trying to ease into target while targeting a mesh for mesh rotation instead of model center rotation (arch rotate cam). We have allowed upside down so the model can rotate around the Y axis fully. When I target a mesh along the alpha it set targets correctly and eases in. however if i move the model far along the beta it will flip it when I target the mesh.
I’ve been looking at the camera postion and played around with that but it seems strange why it is doing this. Does anyone have any ideas please?
https://playground.babylonjs.com/#7F6S08#33
export function targetMesh(scene, camera, defaultTarget) {
//use scene picking ray to detect mesh for camera target
const ray = scene.createPickingRay(
scene.pointerX,
scene.pointerY,
BABYLON.Matrix.Identity(),
camera
);
const hit = scene.pickWithRay(ray);
const speed = 100;
const ease = new BABYLON.SineEase();
const previousTarget = camera.target;
if (!hit.pickedMesh) {
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
// BABYLON.Animation.CreateAndStartAnimation('at4', camera, 'position', speed, 120, camera.position, global_position, 0, ease);
BABYLON.Animation.CreateAndStartAnimation('at5', camera, 'target', speed, 120, camera.target, defaultTarget, 0, ease);
} else {
const targetEndPos = hit.pickedMesh._boundingInfo.boundingBox.centerWorld;
// hit.pickedMesh.computeWorldMatrix();
// var matrix = hit.pickedMesh.getWorldMatrix(true);
// var local_position = targetEndPos
// local_position.addInPlace(targetEndPos);
// var global_position = BABYLON.Vector3.TransformCoordinates(local_position, matrix);
// camera.setTarget(targetEndPos);
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
// BABYLON.Animation.CreateAndStartAnimation('at4', camera, 'position', speed, 120, camera.position, targetEndPos, 0, ease);
BABYLON.Animation.CreateAndStartAnimation('at5', camera, 'target', speed,120, previousTarget, targetEndPos, 0, ease);
}
}
these are the corridnates before and after the flip:
camera e {x: 51.70818065172034, y: -2476.129942213039, z: -19806.38342037944}
camera e {x: 51.708180651442035, y: -2476.12994221302, z: -19806.38342037942}
I can see the end decimals have changes and one added to X but nothing else jumps out at me
Last point, I’ve played around setting the camera position too but still having a similar issue. seems like when it rotates to far over or under the Y (beta) it loses track of its cords and reverts me back to something it can handle