How do I use acceleration/deceleration as a condition?

0 favourites
  • 6 posts
  • Hi everyone, I started using Construct 2 yesterday and although it's great, I've been stuck on this same issue for hours now.

    Basically, I'd like to make a platformer, and I would like for the character to have running animation and a stopping/turning animation.

    I would like for the turning animation to play whenever the character is decelerating. I.E. Either running in one direction and then pressing "run" in the opposite direction, or running in one direction and then stopping.

    Once the character starts accelerating again, the normal run animation would play. So the sequence would go:

    1. User presses "right"

    2. Character runs right, with the "Run" animation playing

    3. User presses "left"

    4. Character starts to decelerate, with the "stop/turn" animation playing

    5. Character very briefly comes to a full stop

    6. Character starts to accelerate left, with the (mirrored) "Run" animation playing.

    OR

    1. User presses "right"

    2. Character runs right, with the "Run" animation playing

    3. User releases "right" and presses nothing

    4. Character starts to decelerate, with the "stop/turn" animation playing

    5. Character comes to a stop and enters the "Idle" animation

    I've tried everything I can think of, including some truly weird attempts involving setting global variables as delayed assessments of Physics velocity. Which failed hilariously. Can anyone let me know what I'm doing wrong?

    Thanks!

  • Well, two possibilities spring to mind - you can on each tick preserve the previous velocity and compare it with the current to see for changes. Or you could just monitor the changes is the presses to determine it - your own pseudocode specifies it in terms of what is or isn't pressed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks! Preserving the old velocity and comparing for changes is actually what I was trying to do with the global variable thing- is there somewhere that would help me to figure out how to do it? I haven't been able to figure it out so far, and can't find anything either.

    That seems like the a decent way to solve the issue so if I could figure that out I'd be pretty happy.

    Edit: I should probably elaborate: What I had done was create an event where, when the player's speed was < 0, it would assign the speed to a global variable, wait a second, and then compare that global variable to the new current speed. For some reason, they always worked out equal.

  • I'd put it as an instance variable of your object. Initially give it the value of 0 I would think, and every tick compare it against the horizontal velocity component which should be a member value in the behaviour, VectorX if you are using Platform which it sounds like you are. You might want to check it works first by displaying it in Browser.log or a debug text, just to check it is doing what you think it is.

  • It worked perfectly! Thanks very much, I didn't know that VectorX worked the same as Velocity in that left movement was negative!

    Cheers!

  • Hey, could you guys go into more detail in what you're talking about? I know what to do I just don't know how to show it to Construct 2 to get it to work.

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