Jump to content

Smooth FollowCamera transition between targets


simon_bg
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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... 

...

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...