How do I prevent camera lag when object is on layout edge.

Get help using Construct 2

Post » Sun Jun 19, 2016 11:03 am

My problem is the camera. I want the camera object to stop moving at the same time the view-port edge hits the edge of the Layout. Currently the camera stops when the view-port edge gets to the edge of the layout and the camera object keeps going. Once I start moving the camera object in the opposite direction there is a small lag before the camera starts moving with the camera object again.

Is there a simple way to fix this? The camera isn't attached to a player object. The "Player" of the game is controlling the hidden camera object at all times. The only way I thought of fixing this was having a camera object mimic the movement of a hidden player object, but at a different rate of speed than the player object. If both objects start at the same spot in the middle of the layout, then no matter what path is taken they will always be on top of each other in the middle of the layout. I know this will cause the distance between them to get rather large depending on the size of the layout. I am going to defeat that using layout width/height in the formula. I just need a simple sample to have different speeds, I can do the harder math parts to fix the gap.

I would like an easier solution, but if one isn't available I just need an example on how to have an object mimic another object at a different rate of speed. I am not talking following the exact same path, just mimicking 8 way movement.

Is it possible to just set a hard x and hard y limit? Camera Object can only move between X20 - X2000 and Y20 - Y2000? If so I will incorporate Layout Scale to help soften the limit.


Thanks in advance.
Last edited by Unconnected on Sun Jun 19, 2016 11:26 am, edited 1 time in total.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Sun Jun 19, 2016 11:22 am

you could just add conditions to the event.

cameraObject.x < OriginalWindoWidth/2 +1
cameraObject.x > layoutwidth-(OriginalWindoWidth/2)-1
scrollto - cameraObject.x

when the center of the scroll is at the edge camera object shouldn't move

something like that i think would work.
and same for y if game scrolling that way also.
Last edited by tunepunk on Sun Jun 19, 2016 11:29 am, edited 1 time in total.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,024
Reputation: 13,345

Post » Sun Jun 19, 2016 11:49 am

You are right about the WindowWidth. It keeps the object in middle of the Window and if the Window edge touches the Layout Edge the camera stops. I get it now, I wasn't thinking correctly. I have to set up variables and then limit the objects movement with the variables.


One Question still remains. I have a slide on the camera. I don't want it to suddenly stop, Is there a way to prevent directional input from the player? A soft limit instead of a hard limit?

Thanks.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Sun Jun 19, 2016 12:01 pm

probably that's a bit more tricky. But i think you could decrease the lerp step based on how close you are to the edge, so it would have the feeling that it slows down close to the edge, not completely stop quickly.

I think you would need a lerpStep variable that changes based on the distance to the edge.

not really sure how to do that, but I can try. give me a moment.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,024
Reputation: 13,345

Post » Sun Jun 19, 2016 12:20 pm

I logged off already. Can't check any capx soon. I wasn't expecting a reply so soon.. I was thinking camera when I posted this, wasn't thinking of camera object. I can probably take 2/5th of the window size and Lerp it using the edge of the Layout somehow. I'm sure I will need an example though. I just found out how to use lerp today and not 100% sure the different ways it can be applied. I actually already had events to do lerp in place. Glad I can remove them. I won't be able to reply or view capx to soon. Didn't mean to start conversation then run... Sorry about that, and Thanks for the help.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Sun Jun 19, 2016 12:28 pm

I suppose I could set a hard limit and then Add/Subtract from Camera Object X/Y to cause it to slow down. The only issue is the slide will be different, unless someone knows how to translate 8direction deceleration into X/Y value.... I have to leave now.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760

Post » Sun Jun 19, 2016 12:50 pm

Image

This way you can set the lerp value to decrese close to the edges so that it will never have a sharp bump. Always smooth even when hitting the layout edge.

the disbottom,top,etc sets the distance to all the edge.

lerp step picks the lowest of these values and limits it too 200, the devides to get a good lerp value.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,024
Reputation: 13,345

Post » Sun Jun 19, 2016 1:21 pm

Image

Works better if you have 2 lerp values, otherwize you get strange behaviour if you are moving along an edge.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
18
Posts: 1,024
Reputation: 13,345

Post » Thu Jun 23, 2016 11:51 pm

Sorry for the late reply. Thank you for your time. I am small bit confused.

Why are you using OriginalWindowWidth/Height and not WindowWidth/Height?

Is 200 and 2500 just based off of the Layout Size?

Why are you setting LerpStepX and LerpStepY what are they used for?
It seems like they are being used elsewhere but isn't being shown.
B
67
S
37
G
13
Posts: 241
Reputation: 12,760


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests