# Need help with interpolation formula

0 Favourites
• 4 posts
• Hello

I have three objects. the camera, the player and the destination.

Every tick the camera follows the player with a lerp motion.

Every tick-> camera set Y-> lerp(self.Y, player.Y, 0.05)

Now after an event triggers I need the camera to go to the destination instead of the player.

After event trigger->

Every tick-> camera set Y-> lerp(self.Y, destination.Y, 0.05)

Doing so causes a 'jerk' in motion when the camera switches from the player to the destination. I believe this is because of the interpolation variable (0.05 in the above case) as the distance between the player and the destination causes the camera to gain or lose speed.

How can i calculate the the interpolation variable to be put in the event ( when the camera switches from player to destination or vice versa) ?

Are there any better workarounds?

Thank you

• You want the camera to smoothly transition? If so, you will need an intermediate event that transfers your frame of reference from self/player to self/destination.

Something like: lerp(self.Y, lerp(player,Y, destination.Y, x), 0.05), then increment x from 0.0 to 1.0 and then transition into your next event.

• Thank you very much!!

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Well, thank me if you can get it working, lol. It is just a theory right now. You will have to massage it a good bit to actually get it working.