Lerp vs Parallax

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

    My event is something like this:

    EVERY TICK
    Camera > Set position to lerp(Camera.X, Player.X, 3*dt), lerp(Camera.Y, Player.Y, 5*dt).  [/code:28ako3ze]
    
    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.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 :

    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 [/code:75y8x6ac]
    
    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.
  • 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.

  • ome6a1717 : is the pixel rounding option on in your project? It causes the objects to only be rendered at integer positions.

  • Valerien - you sir, are brilliant. Thank you!

  • ome6a1717 : thanks! I'm glad your issue could be solved.

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