# Trying to recreate 2d sonic running animation

In your event 5 you set speed as a scene variable, but in the events 3.1.1 and 3.1.2 you use an object variable. Check my image again.

Well, ichange as you says

imgur.com/a/YGotE

now my character does that:

imgur.com/nxniaYy

When he runs from the left to the right, he does the “Course” Anim’, but kinda skip the “Debut Course” one…

It just need a little touch:
1 - The variable speed can be positive or negative, when you run to the left it’s negative so it will always be < max speed, that’s why it doesn’t run to the left. To fix it, when you calculate the speed, instead it:

``Do = (Jouer.X() - Variable(prevX)) / TimeDelta() to the variable speed``

make it always positive (just add an abs()):

``Do = abs( (Jouer.X() - Variable(prevX)) / TimeDelta() ) to the variable speed``

2 - When you run to the right the player sometimes runs and sometimes doesn’t, it’s because this method is an approximation, and you are asking the speed to be exactly the max speed to make it run, checking exact values is a bad idea when you work with floats. To fix it add a little range to the values:

[code]Conditions: Variable speed is < Jouer.PlatformerObject::MaxSpeed() - 5
Actions: Set animation “walk”

Conditions: Variable speed is > Jouer.PlatformerObject::MaxSpeed() - 5
Actions: Set animation “run”[/code]
Note that I ask the speed to be greater (not equal) than the max speed - 5
The “max speed - 5” is a little range to cover the approximation error, but the 5 is arbitrary, if I remember correctly the error was very small, maybe it works if you use “max speed - 1” or even 0.1 or 0.001, just try them out

Now my events look like that:

imgur.com/a/vnLqI

But we’re back to the situation before, the run isn’t appearing, the character only walks…

Delete the whitespace between “abs” and “(”

Thanks it works. I just need to make the walk animation longer, and it will be perfect

Play with the acceleration and max speed values

I was able to make it smooth now, it’s not exactly like the original games, but it’s nice!!! Thank you.

Out of curiosity, Sonic, normally, has an animation that happens when he suddenly change of direction and so, decellerating, he drifts a little before turning to the other direction.

An idea how to do that with events?

Ah, I was worried that might be the case. I didn’t have time to test it.

Not so much, I guess you’ll have to deactivate the default platformer controls and simulate them through events (there are examples about how to do it out there), then you’ll have more control on the keys pressed. Finally, for example, when you press Left but you are running to the right, instead simulate the left key for the platformer (which will make the player run to the left automatically) you can set the brake animation and reduce the max speed, when the max speed is very low simulate the left key and restore the max speed.
I’ve never tried it so no idea if something like this can work

Luckily almost everything has a workaround

I wonder if the “Key is released” condition might be useful for doing a little skid before changing direction? Add a little horizontal force according to whether the "move right or “move left” key is released?

I guess so, but Sonic’s brake animation can take a second or more (depending on the speed before brake), and he won’t walk or flip direction until totally stop

Well for now i can do without the brake animation. It’s not my priority, i just wanted to know if it was possible haha!!

Whatever, thank you all.

Now i will work to make him do Spin Dash, and then i will start working on the loop thing.