Discuss Scratch

conducter_kid
Scratcher
61 posts

Platformer Animation

Hello! I am making a platformer but I figure out how.
In my platformer you will be able to walk, roll, and get hit or die but I can't figure out how to animate the player.

If I use

when green flag clicked
forever
if <key [ right ] pressed?> then
next costume
end
end

It will walk, and get hit, and roll because all the costumes are in the same sprite.

If I do this

when green flag clicked
forever
if <key [ right] pressed?> then
switch costume to [ walk 1]
switch costume to [ walk 2]
switch costume to [ walk 3]
switch costume to [ walk 4]
switch costume to [ walk 5]
end
end

Then it will work pretty good but if I press the right arrow for a longer time it will play the five costumes but then stop and the character will move while being still.

If anyone knows how to fix this that would be awesome!

Thank you!
FlameyBros
Scratcher
8 posts

Platformer Animation

You can google a tutorial on animations as they go into more detail, but I am sure a simple solution like this should work
when green flag clicked
forever
if <key [right arrow] pressed?> then
if <[costume #] > [5]> then
next costume
else
switch costume to [walk 1]
end
end
end

This will loop the animation when the player pushes the right arrow and stop when it doesn't

Last edited by FlameyBros (Oct. 13, 2024 17:10:50)

conducter_kid
Scratcher
61 posts

Platformer Animation

Wait. It still plays all the costumes like roll and hit so if I press the right arrow it will walk, roll, and hit…

Last edited by conducter_kid (Oct. 13, 2024 17:34:09)

Imakegamesalot
Scratcher
53 posts

Platformer Animation

for the second one, is the issue that the costumes stop changing or the costumes keep changing when the character stops? Also, if it's a platformer and you have an X variable you could (maybe) use:

if <key [right arrow] pressed> then
next costume::looks
if <(costume #) > [5]> then
Switch costume to [walking one]
end
end

not sure if that'll have the same problems bc im too lazy to test it, but i hope it helps!

I still haven't figured out how to do a signature
conducter_kid
Scratcher
61 posts

Platformer Animation

It doesn't work…
conducter_kid
Scratcher
61 posts

Platformer Animation

Hmm… Maybe I'll look at a tutorial.

If you have any ideas, please reply!
conducter_kid
Scratcher
61 posts

Platformer Animation

:)

FlameyBros
Scratcher
8 posts

Platformer Animation

conducter_kid wrote:

Wait. It still plays all the costumes like roll and hit so if I press the right arrow it will walk, roll, and hit…
Could you go into more detail? maybe send some images of your costume and your code? I don't understand the problem..

You have to change the number of costumes you have for the walking animation and change the costume to the beginning walking costume

Last edited by FlameyBros (Oct. 13, 2024 18:11:14)

invalidaccess
Scratcher
100+ posts

Platformer Animation

i made this example project to demonstrate character animations in platformers
https://scratch.mit.edu/projects/1073927514/
everything explained in the editor
if you have any question just ask
JacksterBobster
Scratcher
91 posts

Platformer Animation

Here's an idea, instead of having each animation in a separate script, have them all in one by using custom blocks. Just make sure that the “Run without screen refresh” checkbox is left unchecked

when green flag clicked
forever
animate
end


define animate
if <player is hit> then
switch costume to [player is hit v]
stop [this script v]
end
if <player is rolling> then
switch costume to [player rolling v]

switch costume to [player rolling 2 v]

switch costume to [player rolling 3 v]

else
if <player is walking> then
switch costume to [player walking v]

switch costume to [player walking 2 v]

switch costume to [player walking 3 v] // you can add as many of these as you want

end


end

Keeping them all in one script will ensure that the sprite does not try to switch its costume twice in one frame, leading to it looking like no change at all.
The issue with the sprite still animating after letting go of the button is still present with this method, just warning you, but if you know how to use variables correctly you can remove it.
WafflesYouTubeMC
Scratcher
500+ posts

Platformer Animation

I'm having a similar problem, expressed more here: Scratch Forums Post Can anyone help me?
happyyear2024
Scratcher
10 posts

Platformer Animation

By using the timer and * calculation
happyyear2024
Scratcher
10 posts

Platformer Animation

So like this
switch costume to [ (((timer) * (5)) - (put how many costumes are above the first costume))) v]

Powered by DjangoBB