How to invert lerp Scroll To Position

0 favourites
  • 8 posts
From the Asset Store
All popular touch mechanics - scrolling, zooming, swiping
  • hi,

    can't figure out how to do this...

    currently I'm lerping the scroll position so that it lags behind where the player was(the player is moving on an Unbound layout).. when the player stops moving the Scroll catches up nicely. However.. I'd like it to work the opposite way.. I'd like the camera to proceed the player (when moving) so the player can have more room to see what is coming.

    currently it's Scroll To... lerp(scrollx, Player.x, 2*dt) which lags behind the player... when the player stops, or moves slower, the "Camera" catches up. I want to keep that.. I just want the whole thing inverted. So when the player is going the fastest to the right, the player is to the left of the screen, then when stopping, the camera should slowly move to the Player.

    Here's a capx...

    any help would be be greatly appreciated! Thanks..

    https://dl.dropboxusercontent.com/u/362 ... croll.capx

  • lerp(scroll.x,Player.x+player.speed,2*dt)

  • newt that's not quite right...

    the player can move 360 directions and the way it is now, when the player is at full speed (let's say going up) the player is positioned around halfway from the center of the screen to the top of the screen. When you let go of the arrows, the camera catches up and the player is center of the screen.

    Instead - I want the player halfway from the center to the bottom of the screen (while traveling up). So basically the player is facing the center of the screen "trying to catch it"... not until you slow down are you centered.

  • newt okay I figured out what you meant..

    ScrollTo.... lerp(player.x , player.x + (player.speed * 2), 2*dt)

    so yeah this works (kinda, it's still off to the left) but when going up or left it's totally off... sort of the right idea.. but not quite..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The trig would be

    lerp(scrollx,player.x+sin(player.angle)*speed,2*dt)

    And

    lerp(scrolly,player.y+cos(player.angle)*speed,2*dt)

  • The trig would be

    lerp(scrollx,player.x+sin(player.angle)*speed,2*dt)

    And

    lerp(scrolly,player.y+cos(player.angle)*speed,2*dt)

    that didn't work either..thanks for trying..

    I'm seeing your thinking though..

    the way I think of how it is currently...

    Way #1: the plain old lerp(scrollx,playerx) this is sort of like the player is dragging the camera around after him... so no matter what direction/position the camera is just trying get back to the center and the player is "out running the center" with speed (the speed is capped so the player doesn't ever get completely off screen).

    Way #2: I need come up with a way for the player to instead "push" the camera, but it has to be a calculation that has speed as a factor, so that when the player stops, the player then catches up with the camera.

    In the first instance we have scrollx and scrolly which is always the center of the screen. But in the 2nd case we don't have that constantly updated fixed point. It's like I need to create an invisible sprite that's in front of the player and it's distance is binded to the player's speed. but obviously there's a match solution. R0J0hound?

  • Sorry had it reversed.

    lerp(scrollx,player.X+cos(Player.8Direction.MovingAngle)*Player.8Direction.Speed,2*dt)

    lerp(scrolly,player.Y+sin(Player.8Direction.MovingAngle)*Player.8Direction.Speed,2*dt)

  • Sorry had it reversed.

    lerp(scrollx,player.X+cos(Player.8Direction.MovingAngle)*Player.8Direction.Speed,2*dt)

    lerp(scrolly,player.Y+sin(Player.8Direction.MovingAngle)*Player.8Direction.Speed,2*dt)

    oh! haha.. I didn't even think of that! yup totally works... I knew that should have worked! thanks!

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