# Math Help: lerp to compensate for parallax

Get help using Construct 2

### » Thu Apr 30, 2015 3:18 pm

hi..

I have an unbound layout and I'm making it an infinite scroller (360 degrees). I have that part working fine, however I want to make the tiled background's parallax 125,125 (to show faster movement than is actually happening). So now I need to do a calculation to correctly "scroll" the background. My guess is I need to compensate or "undo" the linear extrapolation the parallax layer is doing...

Since the parallax layer is scrolling 25% faster, the distance between the game layer (100,100) becomes exponentially further apart. The X of the game layer and X of the parallax layer will show as if they are on the same layer, but visually it will look different.

I've seen lerp examples of the opposite of this, I'm having trouble seeing how to reverse it.

can anyone help?

here is the capx: https://www.dropbox.com/s/wc25q2e3m1vph ... .capx?dl=0
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Thu Apr 30, 2015 4:25 pm

I got a little closer.. I'm able to match the parallax layer, but still can't figure out how to add to compensate for it.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Thu Apr 30, 2015 4:51 pm

Try not using parallax.
Place it all on one layer, and give the bg a slower speed.
25% slower than the player.
B
173
S
50
G
194
Posts: 8,562
Reputation: 121,360

### » Thu Apr 30, 2015 5:00 pm

@newt the player is moving, not the background.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Thu Apr 30, 2015 5:04 pm

got closer, figured out the invert of the parallax.. I had to lerp using the inverse (75% instead of 25%) to compensate.

now it's just figuring out the scrolling. Normally you set the position of the tile to a multiple of 32, but in this case I think that also needs to be lerped?
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Thu Apr 30, 2015 5:20 pm

@R0J0hound any chance you could take a look? capx is in the op
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Thu Apr 30, 2015 7:42 pm

You should be able to convert an x on a paralex layer to an x that is visually the same as an x of a non paralex later with something like:
X + (scrollx-view_width/2)*layer_paralex_x/100
And similarly for y.

Also alternatively there are some system expressions to do the conversion: Layer2canvas and canvas2layer.
B
94
S
33
G
128
Posts: 5,489
Reputation: 81,541

### » Thu Apr 30, 2015 7:46 pm

okay I think I have the Trigger correct (not totally sure).. I'm triggering the infinite scroll to happen when the player reaches the halfway point of the TB (tiledbackground). To compensate for the parallax, I'm calculating where the player would be if it were on the same layer.

My problem is still with Setting the Position of the TB relative to the player's layer. It feels like I have to do the opposite calculation, but that's not working.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Thu Apr 30, 2015 7:48 pm

@R0J0hound thanks, I didn't know about those.. I will look into that! it does seem like there should be an easy way to calculate between parallax layers.. I feel like I'm reinventing the wheel..
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

### » Thu Apr 30, 2015 9:49 pm

@R0J0hound I don't understand what the canvastolayer values are.. CanvasToLayerX(layer,x,y) there is no doc on this that I can find. I printed out the values and they don't make any sense..

I tried your other calc: player.X + (scrollx-layoutwidth/2)*layer_parallexX/100
but that value doesn't make sense either...

I'm ready to give up on this... what a pain!
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

Next