0 Favourites

Math Help: lerp to compensate for parallax

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

  • 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.

  • Try not using parallax.

    Place it all on one layer, and give the bg a slower speed.

    25% slower than the player.

  • newt the player is moving, not the background.

  • 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?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • R0J0hound any chance you could take a look? capx is in the op

  • 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.

  • 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.

  • 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..

  • 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!

  • my work around is to make the tiled background 40,000x40,000 and somehow push the player back when they get near the edge -- otherwise it will look really bad if the parallax just ends...

  • okay I think I figured out the problem. compensating with lerp gives a number that is not divisible by 512... so I have to bring it to the nearest multiple of 512...

  • You use the layer2canvas expression first, the parameters are fairly straight forward, it uses x and y because it also takes into account rotation as well. After that you use the canvas2layer expression to convert the coordinates to another layer.

    the other expression wasn't tested which could explain it not working.

    You could try newts sugestion and just move the background by giving it the bullet behavior and setting its angle of motion to be opposite to the players angle of motion. You then would set its speed to 0.25*player.speed to get the same visual effect a paralex, except on the same layer without the need for coordinate calculations.

  • You could try newts sugestion and just move the background by giving it the bullet behavior and setting its angle of motion to be opposite to the players angle of motion. You then would set its speed to 0.25*player.speed to get the same visual effect a paralex, except on the same layer without the need for coordinate calculations.

    I'm not sure how that would work on an unbound layout. The player also can move 360 degrees. Eventually the player will overtake the TB, then what? I would still need to reset the tile over the player, which is what I am doing now.

    I have it working except for one small glitch. right at the beginning there's a jump... it's somewhere when the calculation starts..

    Here's the latest:

  • figured it out..

    I was starting the TB at x:940y:540... it needs to start at x:1024y:512 since I'm doing all my math with 512...

    WoW... that feels good..

    although I'd like to do away with the dummy TB. I could probably replace it with a calculation or variable as I was just using it visually to see what was going on... it looks interesting to have both TB visible..

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)