Lerp Camera is causing trembling

Get help using Construct 2

Post » Sat Jun 27, 2015 3:38 am

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 !
B
5
S
1
Posts: 19
Reputation: 415

Post » Sat Jun 27, 2015 5:33 am

Try using the Lerp command without the dt, it worked pretty smooth for me.
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Sat Jun 27, 2015 6:10 am

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.
B
5
S
1
Posts: 19
Reputation: 415

Post » Sat Jun 27, 2015 3:31 pm

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.
B
5
S
1
Posts: 19
Reputation: 415

Post » Sat Jun 27, 2015 5:17 pm

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
Code: Select all
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)


I know I have a really wonky lerp, but that might help in some way.
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Sat Jun 27, 2015 5:57 pm

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 ?

Thank a lot for your answer and your help :)
B
5
S
1
Posts: 19
Reputation: 415

Post » Sun Jun 28, 2015 4:21 am

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.
Be sure to check out my Metroidvania game, A Hole in the Earth
B
59
S
24
G
3
Posts: 359
Reputation: 5,683

Post » Sun Jun 28, 2015 6:06 pm

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:
Image

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Tue Jun 30, 2015 4:26 am

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 !
B
5
S
1
Posts: 19
Reputation: 415


Return to How do I....?

Who is online

Users browsing this forum: David181, InfiniteRockets and 16 guests