Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make a sprite Jump and move at the same time.
- ScratchesBoi
-
3 posts
How to make a sprite Jump and move at the same time.
I know how to make a sprite jump using variable but when the sprite is jumping, it can move. If I'm moving when i jump, it just stops moving and jumps. Please help. Thank You.
- UnconstructivePoster
-
100+ posts
How to make a sprite Jump and move at the same time.
Can you share the project and provide a link so we can see your current code and provide more specific feedback?
- ScratchesBoi
-
3 posts
How to make a sprite Jump and move at the same time.
https://scratch.mit.edu/projects/461851725/ Here it is.
- MineralNooodles6664
-
100+ posts
How to make a sprite Jump and move at the same time.
Its pretty simple, just put the movememt and jump script in a separate forever loop.
Hope this helps
Hope this helps
- MineralNooodles6664
-
100+ posts
How to make a sprite Jump and move at the same time.
See the fix here: https://scratch.mit.edu/projects/461898133/ (I made it just for you)
- UnconstructivePoster
-
100+ posts
How to make a sprite Jump and move at the same time.
I think the main problem with your current script is the repeat blocks in both the movement and jumping sections of your script. When the project runs a loop, it runs through every iteration of that loop until it's done, before continuing with the rest of the script, and that's why your current code doesn't let you move and jump at the same time: when you press space, the repeat until block starts running, and the script doesn't move on until it stops, so your movement code is unable to run at the same time. (You may also notice that you can't jump while you're moving: this is for the same reason.)
One way to fix this could be to separate the movement and the jumping into separate forever loops; however, the solution that I'd personally recommend is removing all the repeat loops and making it so that the y-velocity decreases on every iteration of the forever loop, not just when the player is jumping. You would need to add another way of detecting when the player is on the “ground”, but with your current code that should just be a case of checking if y position < some #.
Edit: ninja'd
One way to fix this could be to separate the movement and the jumping into separate forever loops; however, the solution that I'd personally recommend is removing all the repeat loops and making it so that the y-velocity decreases on every iteration of the forever loop, not just when the player is jumping. You would need to add another way of detecting when the player is on the “ground”, but with your current code that should just be a case of checking if y position < some #.
Edit: ninja'd
Last edited by UnconstructivePoster (Dec. 10, 2020 15:04:38)
- Discussion Forums
- » Help with Scripts
-
» How to make a sprite Jump and move at the same time.