How do I check if a value has been changed?

0 favourites
  • 4 posts
  • I have spent the last two hours banging my head against the wall trying to figure this out on my 2D platforming game.

    I want to be able to tell when my character changes direction from left to right. The reason for this is, when my character suddenly changes direction, the run animation will pause for 0.5 seconds on a specific frame to make the character skid a little before running the opposite direction.

    So, in a nutshell, this is the sequence of events:

    Character is running right -> User presses left -> Sprite animation pauses for 0.5 seconds -> Character runs left.

    Likewise, the reverse will be true also:

    Character is running left -> User presses right -> Sprite animation pauses for 0.5 seconds -> Character runs right.

    I can't figure out how I would create an event for this.

    Any guidance or direction would be so helpful.


  • I'm sure there are better ways to do it. The first thing I can think is that you would need two variables:

    - detect in real time which button is pressed (left or right)

    - delayed variable that check evert 0.1 second in which direction the player walk (if player is moving, and right is pressed, then is right. Or, if the player is moving, and is not mirrored, then is right...etc.)

    Then, you compare these two variables to detect when the player changes direction.

    If real time variable is left (the button is being pressed) and the delayed variable is right (because it takes 0.1 sec to turn left) then you know that the player is turning left from the right position. At this point, you can make a boolean which is true, to the action you need to do, and set the boolean back as false. Of course, while the boolean is active you can disable the two actions I described above. When the animation of the player ends, set the boolean to false.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • if player is on floor and player.platform.vectorX>0 and keyboard press left. Set animation to "skidding" wait 0.5 simulate platform pressing left.

    VectorX gives you the vertical speed of the platformer object. greater than 0 means right, less means left, maybe that helps? with this you even could do skidding only if the VectorX is faster than x.

  • Thanks both. It's finally working!

    I didn't realise how much work was involved to create a really fluid and robust character movement. There are so many edges to consider.

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