Preserving speed on lerp

Discussion and feedback on Construct 2

Post » Sun Sep 06, 2015 5:16 am

If I do something like this:

Code: Select all
Set Position of Camera
X - lerp(Camera.X, TargetX, XLerp*dt)
Y - lerp(Camera.Y, TargetY, YLerp*dt)


and I set TargetX and TargetY to Player.X and Player.Y, how would I retain the speed the camera is traveling if I decide to change the targetX and Y to something else so I don't get a jerk movement from the camera?
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Tue Sep 08, 2015 4:10 pm

So I think I've figured out that using an updating lerp value (ie Camera.X and Camera.Y) might not be the best approach for this, but any other way doesn't feel smooth enough to me (also tried rex's moveto behavior). Any other suggestions?
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Tue Sep 08, 2015 5:34 pm

I am not sure about what you are trying to achieve. The most basic camera movement using lerp is based on the formula lerp(scrollX, player.X, a value between 0 and 1). Why isn't this smooth enough..?
Here are some examples based on the same principle https://www.dropbox.com/s/4zjv1n9924fpf ... .capx?dl=0

There is also a camera plus plugin, perhaps it fits more to your needs. Check it out on the plugin section of the forum.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Tue Sep 08, 2015 8:50 pm

@eli0s - the camera lerping is all fine and smooth. What happens is when you change targets, you get a "jerk" because the lerp value isn't changing. So I would have to change the lerp value but I'm not sure how to calculate it based on the distance.

Maybe that helps making things clearer?
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Tue Sep 08, 2015 10:46 pm

Hmmm... I don't really get what the problem might be... Perhaps it's a picking problem? The way you choose and alternate between targets might affect the scrolling system. If you post an example of what you want to achieve, perhaps someone might be able to figure out what is going wrong.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Wed Sep 09, 2015 5:35 am

@eli0s - here's a rough example of what's happening.

https://dl.dropboxusercontent.com/u/28104568/CameraExample.capx
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Wed Sep 09, 2015 9:06 am

I see what you mean now... What you need is a way to ease the transition from one camera state to an other. I am afraid I can't think of anything in particular that can improve upon your example... I tried the Lite tween Behavior but it doesn't help much in this case: https://www.dropbox.com/s/80uccb40dm0z5 ... .capx?dl=0

I believe the problem lies in the linear interpolation between the Camera.X/Y position and the Camera.Trigger.X/Y position. You can move around your mouse in circles and the camera Sprite follows smoothly, but when you Overlap the CameraTrigger, the camera jumps towards it in a straight line, and that is what causes the irregular movement. You'll need a way to curve from mouse.X/Y position toward Camera.Trigger.X/Y position, unfortunately, I don't know how to do something like this... :(
composer - multimedia artist
www.eli0s.com/en/
B
69
S
26
G
5
Posts: 1,146
Reputation: 9,829

Post » Wed Sep 09, 2015 2:57 pm

This might help? I never understand how you're supposed to translate this stuff to C2 :T
Image
B
243
S
30
G
13
Posts: 1,787
Reputation: 18,770

Post » Wed Sep 09, 2015 4:17 pm

@eli0s - Yeah, it's a tough one. My original idea was to change the XLerp and YLerp the second you overlap the trigger, but the question remains; what do you set it to so it's smooth no matter what speed you're at? I looked at your example; it actually is pretty good, but has the opposite problem. Going INTO the trigger is fine, but pulling out is a little "jerky".

@Tokinsom - I thought about something like this, but everytime I look at equations like this, my head literally explodes.
B
40
S
12
G
1
Posts: 532
Reputation: 4,147

Post » Thu Sep 10, 2015 12:27 am

My advice would be to create an event driven behaviour for the camera object, so you control every aspect of its movement: acceleration, deceleration, time to pan to x/y, follow offsets etc. Then, if you change the target, the camera just moves like a physics object (as in it accelerates / decelerates, has a max pan speed etc) without any jerky effects. The lerp is ok to start with but I cannot think of an easy way to use it and do what you're asking here. There's also a camera plugin, IIRC, which is pretty excellent....
A big fan of JavaScript.
B
74
S
20
G
69
Posts: 2,214
Reputation: 43,850


Return to Construct 2 General

Who is online

Users browsing this forum: bobcgausa and 4 guests