Anes Posted May 7, 2019 Share Posted May 7, 2019 I create a function that move a camera through a specific goal : var createScene2=function() { var MyCurve; var MyGoal = new BABYLON.Vector3(0,10,5); var scene = new BABYLON.Scene(engine); var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, Math.PI / 2, 5, new BABYLON.Vector3(0,0,0), scene); camera.attachControl(canvas, true); var light1 = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, 1, 0), scene); var light2 = new BABYLON.PointLight("light2", new BABYLON.Vector3(0, 1, -1), scene); var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {}, scene); MyCurve= MyPath(camera.position, MyGoal); MoveCameraThrough(scene, camera , MyCurve); return scene } when I call the render : var scenee= createScene2(); engine.runRenderLoop(function () { scenee.render(); }); It works fine, but when the camera position arrives to the specific goal, it restarts from the initial point any Ideas ? thanks Anes Quote Link to comment Share on other sites More sharing options...
Anes Posted May 7, 2019 Author Share Posted May 7, 2019 this is my MoveCameraThrough function : function MoveCameraThrough( scene , camera, MyCurve) { const path3d = new BABYLON.Path3D(MyCurve.getPoints()); const tangents = path3d.getTangents(); // array of tangents to the curve const normals = path3d.getNormals(); // array of normals to the curve const binormals = path3d.getBinormals(); // array of binormals to curve const speed = 10*Math.floor(Math.random() * (7 - 3 + 1)) + 3; // const speed = 1 const animationPosition = new BABYLON.Animation('animPos', 'position', speed, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); const animationRotation = new BABYLON.Animation('animRot', 'rotation', speed, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE); const keysPosition = []; const keysRotation = []; for (let p = 0; p < MyCurve.getPoints().length; p++) { keysPosition.push({ frame: p, value: MyCurve.getPoints()[p] }); keysRotation.push({ frame: p, value: BABYLON.Vector3.RotationFromAxis(normals[p], binormals[p], tangents[p]) }); } animationPosition.setKeys(keysPosition); animationRotation.setKeys(keysRotation); camera.animations=[ animationPosition, animationRotation ]; scene.beginAnimation(camera, 0, 200, true); } Quote Link to comment Share on other sites More sharing options...
MarianG Posted May 21, 2019 Share Posted May 21, 2019 Hi @Anes If you didn't do it yet, please post your question here https://forum.babylonjs.com Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.