How do I use acceleration/deceleration as a condition?

Get help using Construct 2

Post » Wed Jul 15, 2015 7:28 pm

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!
B
4
Posts: 4
Reputation: 208

Post » Wed Jul 15, 2015 10:35 pm

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.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Wed Jul 15, 2015 11:43 pm

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.
B
4
Posts: 4
Reputation: 208

Post » Thu Jul 16, 2015 8:21 am

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.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Mon Jul 20, 2015 5:58 am

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

Cheers!
B
4
Posts: 4
Reputation: 208

Post » Tue Nov 29, 2016 11:55 pm

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.
B
4
Posts: 2
Reputation: 206


Return to How do I....?

Who is online

Users browsing this forum: YoHoho and 15 guests