simon_bg Posted December 14, 2017 Share Posted December 14, 2017 Hello guys, I have a scene with a FollowCamera and I need to switch between multiple targets. For some reason though, I cannot get to make the switch smooth. When setting lockedTarget directly it jumps from one position to another. I tried to make an animation with the "lockedTarget" property but it doesn't work. Maybe you guys could help me out? PG: https://www.babylonjs-playground.com/#9AXYDK#1 Thank you! JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
simon_bg Posted December 14, 2017 Author Share Posted December 14, 2017 Okay, I figured it, the solution is quite simple actually. I created an "auxiliary mesh" which I then animated instead of the camera. JackFalcon 1 Quote Link to comment Share on other sites More sharing options...
JackFalcon Posted December 14, 2017 Share Posted December 14, 2017 Hi @simon_bg, Nice avatar, afalcon relates. For comparison, here is smooth camera movement using tween interpolation syntax: // ,cam:{cur:{"x":0,"y":8,"z":-28},tgt:{x:0,y:8,z:-20}, tar:{"x":0,"y":6,"z":0}} asc.animCam = function (tgt,curState,tgtState,dur){ //animates the camera position movement. var tweenCam = new TWEEN.Tween(curState).to(tgtState, dur); tweenCam.onUpdate(function(){tgt.position = new BABYLON.Vector3(curState.x,curState.y,curState.z)}) if(thisScene.cam.ease){ tweenCam.easing(TWEEN.Easing.Quadratic.InOut); } else{ tweenCam.easing(TWEEN.Easing.Cubic.InOut); } tweenCam.start(); } asc.animCamPan = function (tgt,tgtState,dur){ //animates the camera target movement. var curState = scene.activeCamera.getTarget(); var tweenCam = new TWEEN.Tween(curState).to(tgtState, dur); if(thisScene.cam && thisScene.cam.ease){ tweenCam.easing(TWEEN.Easing.Quadratic.InOut); }else{ tweenCam.easing(TWEEN.Easing.Cubic.InOut); } tweenCam.onUpdate(function(){ tgt.setTarget(new BABYLON.Vector3(curState.x,curState.y,curState.z)); }); tweenCam.start(); } It uses time-based-animation with the dur variable, applies various easing functions, and interpolates from CurrentState to TargetState. Would sure like to see your solution... ... Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted December 14, 2017 Share Posted December 14, 2017 https://www.babylonjs-playground.com/#9AXYDK#1 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.