Good day everyone and thank you for spending time on this read.
The illustration of problem from project.
Notes: I need to create camera, wich will follow player on sphere surface in any point and restrictions, so the gimble lock should be blocked, that’s why I can not use arc rotate camera.
Here I create emulation of camera parent and child, add axes to them and record the problem: when I am moving from hexagon to hexagon in minor circumferences of the sphere, it’s works fine. Each 5th render call I am making parent to look at center of the sphere:
this.scene.registerBeforeRender( ()=> {
if(this.renderCount !== 5){
this.renderCount++;
} else {
this.testMesh.lookAt(BABYLON.Vector3.Zero());
this.renderCount = 0;
}
});
This making Z axis (face direction) be perpendicular all the time to sphere surface.
Moving of parent (in the video it presented like plane-sphere under green hexagons).
This is function, which I calls to provide movement of cameras parent.
let testingMovement = function(whatMoving, finishPosition)
let scene = whatMoving.getScene();
let intensity = 15;
let start = whatMoving.position;
let end = finishPosition;
let keys = [];
keys.push({frame:0, value: start});
keys.push({frame:intensity, value: end});
let easingFunctionInOut = new BABYLON.ExponentialEase();
easingFunctionInOut.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
let smoothAnimation = new BABYLON.Animation("move", "position", 15,
BABYLON.Animation.ANIMATIONTYPE_VECTOR3,
BABYLON.Animation.ANIMATIONLOOPMODE_CONSTANT);
smoothAnimation.setKeys(keys);
smoothAnimation.setEasingFunction(easingFunctionInOut);
let animator = scene.beginDirectAnimation(whatMoving, [smoothAnimation], 0, intensity, false);
whatMoving.animator = animator;
animator.syncWith(null); //this animation should be asynchronous;
animator.onAnimationEnd = function(){
whatMoving.animator = null;
whatMoving.animations = [];
animator.stop();
}
};
The problem is, when I am moving in certain points, which probably gimble-lock based (like y = 0), it rotates parent around itself, and this rotating, probably, provided by mesh.lookAt method, so, when here is not mesh, but camera attached as child to parented mesh, it rotates around itself and makes ugly vision, changing angle of view.
I do not know how to fix camera rotation, but I need to achieve movement without changing angle of view by 180 degrees. Like here: Prosecution
But in site source code is extremely hard architecture (for me), that I can not understand when and how they calculating this movement. I will be immensely grateful to some one, who can explain to me how to achieve camera movement like this?