# Lerp Camera is causing trembling

0 favourites
• 9 posts
• Hello everyone,

I'm running into some problems. I created a camera using lerp with that: lerp(ScrollX, Player.X-Xcam, dt*speed))//lerp(ScrollY, ScrollTo, dt*speedY).

It's perfoming nicely expect that when an object is pinned to my player like a pop up dialog the lerp is causing it to tremble slighty left to right.

With the ScrollTo behavior it doesn't tremble. I also tried using 1-f^dt instead of dt*speed in my lerp formula but it's still trembling except when f=0 which kills the effect I wished to have.

I can't keep my camera effect without my objects pinned to the player trembling, is there a third party plugin or a formula which keeps the scrolling steady and not all shaky ? I hadn't see the problem until I pinned object to the player.

I only have a few days to find a solution so if someone has one I would be very grateful !

• Try using the Lerp command without the dt, it worked pretty smooth for me.

• The lerp without dt, just with a variable for a factor isn't smooth at all, it's way worse, the dt is there to smooth it but it doesn't really smooth it enough. It's onyl really smooth when the camera isn't lerping.

I'm actually trying to cheat by using lerp only to change direction (left,right), when the player stops moving or starts to move. And when he is moving and he reaches the middle of the screen the camera would stop lerping and follow him (scroll to: player.x). It makes it smooth when he walks but I can't seem to keep lerp for turning and such whithout the camera jumping from time to time.

If someone has a real solution, please, please, it's been 7 hours of trying things and scouring the web with no result.

• So after trying more I found some things. First the pixel rounding was On and by putting him on Off it seems it trembles way less.

It still trembles when the player change state (moving to not moving, vice versa, jumping to falling...Etc), but it become stable when it reach it's peak. I'm still trying to figure how make it so it doesn't tremble at all.

I'm still taking any advice or knowledge that you would be nice enough to impart me with. I also tried Magicam plugin but it is exactly the same as Lerp expression without as much control on what your camera does, so not a good solution anyway.

• Do you have a camera sprite that you are scrolling to, then setting the position of the camera to the object using a lerp expression?

Here's what I use, and it's slightly different than your camera expression

Every tick---
---System | Scroll to CAMERA SPRITE
---CAMERA SPRITE | Set position to (round(lerp(Self.X, Car.X + (Car.Platform.VectorX / 0.8), 1.015*dt)*10)/10, round(lerp(Self.Y, Car.Y + (Car.Platform.VectorY / 2), 1.021*dt)*10)/10)[/code:2dymhq95]

I know I have a really wonky lerp, but that might help in some way.
• ## Try Construct 3

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

Construct 3 users don't see these ads
• I will try that. The pixel rounding was making the platform behavior jump, without pixel rounding it already way better but the lerp as still some issues and it shakes object that are pinned to the player, I guess the player is shaking also but it's almost unseeable.

I had tried alreayd with a camera sprite but I had the rounding ON so I will try that again. COuld you juste take me through what car.platform.vectorx /0.8 is doing ?

• Wrapping your lerp in a 'round' expression might help you. That way you aren't calculating 4.8653801427978px, but rather 5px.

The Car.X + (Car.Platform.VectorX / 0.8) is just helping the camera look ahead a little bit. So, if you were moving right, instead of your character being in the center of the screen they would be a little bit to the left of center. That way you can see what's further in front of you.

I used vector in the calculation so that the camera moves only when the player is moving, otherwise the player sprite is in the center of the screen since the vector is 0.

• Change up your equation a bit. The trembling is caused by dt varying slightly (like +/- 0.01), and if you have a multiplier on it, it will tremble like that.

Something like this will help to smooth it out some:

This function was generated on https://www.desmos.com/calculator

Using this equation:

\frac{\left(1\ -\ 0.00001^{\left(x-0.5\right)}\right)}{\left(1\ -\ 0.00001^{2\left(x-0.5\right)}\right)}

That way, when dt fluctuates, it will dampen the visible oscillations rather than amplify them.

So you're equation:

lerp(ScrollX, Player.X-Xcam, dt*speed)

becomes:

lerp(ScrollX, Player.X-Xcam, ((1-(1/(100000*speed))^(dt-0.5))/(1- (1/(100000*speed))^(2*dt-1))) )

Then you can try varying your speed between 1 and 10 or so.

• Waaah, thank you very much I will try that. Sadly ryanrybot you formula was as good as mine. Maybe this one will do the trick !