Discuss Scratch

AustralianSpy
New Scratcher
3 posts

Help with jumping animation?

Hi there, this is my first attempt at using Scratch, so bear with me if my code is… ugly and redundant in places. My project is a side-scrolling infinite runner. The scrolling backgrounds and ground all behave correctly. The sprite Runner is scripted to jump when the space bar is pressed. Jumping physics are correct (though will probably be changed). The animation for the jump is not behaving correctly. Upon pressing the space bar, Runner is scripted to switch to the first Jump costume, then repeatedly move to the next costume; once Runner reaches the last Jump costume, the script should stop and the Runner should resume running. Instead, before Runner returns to the first running costume, Runner cycles through all of the Death costumes. I have tried several attempts to stop this, including having the entire Jump animation script stop upon reaching the final Jump costume, or by having Runner switch to the first Run costume after reaching the final Jump costume.

Link to project to see script and animation in action: https://scratch.mit.edu/projects/416313508

Any thoughts? The script is labeled. My only guess was that maybe the Death costume was being triggered somehow, but the only script that allows this requires the Game Over variable to be set to “1”, and a test script calling out when this variable became “1” confirmed that this was not happening. I've occasionally noticed the Death Costumes playing for no reason before, and can never pinpoint why. Maybe it's all related.


Yeah, I know that if you play the game it's still pretty buggy… Glitches I'm aware of (but aren't important right now as it's unfinished):
  • Small objects costumes Trash and Bench do not hide and delete themselves, although potted flowers does.
  • Half-abandoned script to allow runner to run along the top of the bus still triggers because I have not deleted it yet.
  • Dog may or may not crash the game, will look into script inefficiencies.

Last edited by AustralianSpy (Aug. 9, 2020 06:25:23)

MasterBeiber
Scratcher
42 posts

Help with jumping animation?

In the code, you put this:
if <[costume #] > [16]> then
switch costume to [1 Run v]
end
stop [this script v]

Instead, you're gonna want to do this:

if <[costume #] > [16]> then
switch costume to [1 Run v]
stop [this script v]
end

Basically, put the “stop this script” in the “if costume number > 16 then” with the “switch costume to 1 run”.

Last edited by MasterBeiber (Aug. 9, 2020 06:49:44)

AustralianSpy
New Scratcher
3 posts

Help with jumping animation?

MasterBeiber wrote:

In the code, you put this:
if <[costume #] > [16]> then
switch costume to [1 Run v]
end
stop [this script v]

Instead, you're gonna want to do this:

if <[costume #] > [16]> then
switch costume to [1 Run v]
stop [this script v]
end

Basically, put the “stop this script” in the “if costume number > 16 then” with the “switch costume to 1 run”.
Thanks for the suggestion!

The “stop script” block was in the position you indicated because I had been testing out various places to place this block within the script to get it to behave as intended. I've moved “stop script” so the blocks look the way you suggest and have now left it there, however the problem of switching to Death costumes persists.
mstone326
Scratcher
1000+ posts

Help with jumping animation?

Does this remix fix it? Let me know if this is what you were looking to do. I will unshare when you are all set with it.

https://scratch.mit.edu/projects/416730218/
AustralianSpy
New Scratcher
3 posts

Help with jumping animation?

mstone326 wrote:

Does this remix fix it? Let me know if this is what you were looking to do. I will unshare when you are all set with it.

https://scratch.mit.edu/projects/416730218/

Thank you, this seems to do the trick! I've copied the code, as well. So you've basically used a variable to have the two “animation” scripts talk back and forth to each other, right? Running resumes and continues so long as Jump=no. Just for the sake of learning, any idea why the original script I had is unable to execute properly?

Powered by DjangoBB