How do I detect the moment a variable is changed

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have a player with a camera that follows him across rooms until he overlaps an endcap object at the end of the room which locks the camera to not see past the wall. This works great, but the problem is the transition out of the endcap back into the normal room.

    When you leave the endcap the camera needs to return to the correct position to resume following the player, which it does, but very suddenly and ugly.

    The ideal solution would be some kind of condition that can detect exactly when the varible that causes the camera to lock at the endcap goes from true to false so I could smoothly transition with a lerp.

    However, I don't think this exists and an else won't work because it's constant like "If your not overlapping the endcap at anytime, constantly lerp the camera breaking the scrolling" rather than what I need which is "At the moment the 'lock camera' variable becomes false, lerp the camera back in place."

    If anyone has a suggestion or can help that would be lit.

  • You are probably overthinking it. I suggest using MoveTo behavior for the camera - it's more flexible than lerp, you can configure maximum speed, acceleration and deceleration values for a nice smooth movement. And then you can do something like this:

    If variable: Camera Move To (room_center_x, room_center_y)

    Else : Camera Move To (Player.x, Player.y-100)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You are probably right about the MoveTo behavior being more convenient but the else statement is what I currently have in place and it is part of the problem

    This is the current code. When the else is triggered it immediatley disables the camera lock causing the "ScrollX is true" condition at the top to trigger bringing the camera to place instantly rather than smoothly

  • The problem is that you don't use lerp when camlock=false, there is no way to fix it.

    You need to use lerp in both cases. Also change the order of events and use delta-time.

  • Thank's for your help. I had to find a different solution however I didn't know anything about deltatime and now I know how important it is so thanks bro you're a real one

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