Lerp vs Parallax

Get help using Construct 2

Post » Tue Aug 05, 2014 4:50 pm

I have a camera object with "ScrollTo" on it, and multiple background layers that are parallaxing.

My event is something like this:

Code: Select all
EVERY TICK
Camera > Set position to lerp(Camera.X, Player.X, 3*dt), lerp(Camera.Y, Player.Y, 5*dt). 


This works how I want it to, but for some reason if I jump ahead and stop, as the camera lerps closer and closer to the player, the parallax layers seem to only move a single pixel at a time instead of a float (ie 0.4, or 0.01), making it feel weird and choppy. Is this just because of the way lerp works (since it's never actually reaching its destination)?

Slightly off topic it seems to do this when changing opacity as well.

Any insight would be greatly appreciated.
B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Tue Aug 05, 2014 6:06 pm

@ome6a1717, this is due to the fact that with the lerp, your camera keeps moving: on each and every tick, it will target a position that's between its current position and the player's position. You can use the moveTo behavior, or a tween behavior to easily solve that. Otherwise, you will need either a different or a more elaborate system to move your camera. For example :

Code: Select all
local variable posX, local variable posY
posX = Set position to lerp(Camera.X, Player.X, 3*dt), posY = lerp(Camera.Y, Player.Y, 5*dt)

if(position X < 3) Camera, set X to Self.X + 3
else set X to posX
if(position Y < 3) Camera, set Y to Self.Y + 3
else set Y to posY


It isn't very elegant, but it works and extends your lerp operation. I personally use a lerp ratio that varies depending on the position of the camera relative to the main character or element of focus.
B
77
S
22
G
4
Posts: 311
Reputation: 12,634

Post » Wed Aug 06, 2014 2:44 am

@Valerien - thanks. I tried your code, but instead of checking the x and y position of the camera, I checked the distance of the camera and player to see if it's less than 7 pixels, and if so, stop. It helps the problem, but doesn't exactly fix it perfectly. I understand the lerp function makes the camera always moving, what I don't understand is why the parallax only moves at an integer base instead of a float base when the camera is moving.
B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Wed Aug 06, 2014 7:23 am

@ome6a1717 : is the pixel rounding option on in your project? It causes the objects to only be rendered at integer positions.
B
77
S
22
G
4
Posts: 311
Reputation: 12,634

Post » Wed Aug 06, 2014 1:25 pm

@Valerien - you sir, are brilliant. Thank you!
B
38
S
12
G
1
Posts: 526
Reputation: 4,085

Post » Wed Aug 06, 2014 1:36 pm

@ome6a1717 : thanks! I'm glad your issue could be solved.
B
77
S
22
G
4
Posts: 311
Reputation: 12,634


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 7 guests