How to invert lerp Scroll To Position

Get help using Construct 2

Post » Fri Jun 24, 2016 7:54 pm

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
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Fri Jun 24, 2016 7:57 pm

lerp(scroll.x,Player.x+player.speed,2*dt)
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

Post » Fri Jun 24, 2016 10:51 pm

@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.
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Fri Jun 24, 2016 11:05 pm

@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..
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Fri Jun 24, 2016 11:14 pm

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)
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

Post » Sat Jun 25, 2016 12:47 am

newt wrote: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?
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Sat Jun 25, 2016 1:27 am

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)
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

Post » Sat Jun 25, 2016 1:46 am

newt wrote: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!
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003


Return to How do I....?

Who is online

Users browsing this forum: SturmIV and 5 guests