How do I make the camera move to a position where it is looking. Currently I am able to achieve this with animation using camera’s zoom. How do I do the same with position of the camera instead of using zoom?
class Playground
{
static CreateScene(engine, canvas)
{
// This creates a basic Babylon Scene object (non-mesh)
var scene = new BABYLON.Scene(engine);
// This creates and positions a free camera (non-mesh)
camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 900, BABYLON.Vector3.Zero(), scene);
// This targets the camera to scene origin
camera.setTarget(BABYLON.Vector3.Zero());
// This attaches the camera to the canvas
camera.attachControl(canvas, true);
}
}
BABYLON.ArcRotateCamera.prototype.moveRadiusTo = function (newVal, speed)
{
var ease = new BABYLON.CubicEase();
ease.setEasingMode(BABYLON.EasingFunction.EASINGMODE_EASEINOUT);
BABYLON.Animation.CreateAndStartAnimation('at5', this, 'radius', speed, 120, this.radius, newVal, 0, ease);
}
<script>
function MoveCameraPosition()
{
scene.registerBeforeRender(function ()
{
camera.moveRadiusTo(5, 100); //Move camera position+5 metres here
}
}
</script>