Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to make smooth sprite movement + jumping
- TheRealNetherBefore
-
1000+ posts
How to make smooth sprite movement + jumping
I'm trying to make a platformer game where the player character moves really slowly but jumps very high however I want the movement to be nice and smooth- any idea how to do this?
- deck26
-
1000+ posts
How to make smooth sprite movement + jumping
Hmmmmm, the third query in a few days about jumping slowly - is this a bit of school/college work?
- vissaeus
-
72 posts
How to make smooth sprite movement + jumping
use accumulators.
e.g. for move to the right:
forever: set x to, my_X variable
when spacebar pressed my_X variabe must change by 0.1
when spacebar not pressed my_X must decrease -0.1 …. inside this condition if my_X is negative (less than zero). set my_X to zero.
e.g. for move to the right:
forever: set x to, my_X variable
when spacebar pressed my_X variabe must change by 0.1
when spacebar not pressed my_X must decrease -0.1 …. inside this condition if my_X is negative (less than zero). set my_X to zero.
- TheRealNetherBefore
-
1000+ posts
How to make smooth sprite movement + jumping
No, i didn't know anything about that. I just accidentally made the dude really slow then thought it would be cool Hmmmmm, the third query in a few days about jumping slowly - is this a bit of school/college work?
I think I understand what you're saying but I don't really get it… use accumulators.
e.g. for move to the right:
forever: set x to, my_X variable
when spacebar pressed my_X variabe must change by 0.1
when spacebar not pressed my_X must decrease -0.1 …. inside this condition if my_X is negative (less than zero). set my_X to zero.


- deck26
-
1000+ posts
How to make smooth sprite movement + jumping
So are you using y-velocity and gravity to gradually reduce the velocity? Sounds like you want to play with the values in a normal loop of this type
- TheRealNetherBefore
-
1000+ posts
How to make smooth sprite movement + jumping
I don't mean to be rude but this is completely going over my head. So are you using y-velocity and gravity to gradually reduce the velocity? Sounds like you want to play with the values in a normal loop of this type

What I've got so far is a script that changes x by 1 and -1 when going left and right, a script that (using the repeat block) increases the y value when the up arrow is pressed and a script that slowly reduces the y value when not touching the ground.
- deck26
-
1000+ posts
How to make smooth sprite movement + jumping
If you're jumping it's mainly y movement you need - in fact why not ignore x movement for the moment.
So think about gravity in the real world. You fire something in the air and it gradually slows down and then starts accelerating back to earth. So it has an initial velocity (in my script I gave it the value 5) but each time through the loop the amount it goes up should decrease which we achieve by changing the y-velocity by gravity (a negative value). So after the first pass of the loop y-velocity is 4.7, then 4.4, then 4.1 etc and eventually it will right down to 0.2, then -0.1, -0.4 etc so y is going down again at an increasing rate.
The values 5 and -0.3 are what you need to play with to get something you're happy with.
Just try that script and ignore the advice from @vissaeus and anything else you currently have.
So think about gravity in the real world. You fire something in the air and it gradually slows down and then starts accelerating back to earth. So it has an initial velocity (in my script I gave it the value 5) but each time through the loop the amount it goes up should decrease which we achieve by changing the y-velocity by gravity (a negative value). So after the first pass of the loop y-velocity is 4.7, then 4.4, then 4.1 etc and eventually it will right down to 0.2, then -0.1, -0.4 etc so y is going down again at an increasing rate.
The values 5 and -0.3 are what you need to play with to get something you're happy with.
Just try that script and ignore the advice from @vissaeus and anything else you currently have.
- TheRealNetherBefore
-
1000+ posts
How to make smooth sprite movement + jumping
I've done that and I think I'm beginning to understand, but I've encountered another problem- the sprite goes just a bit too far into the ground and won't jump any further -snip-
here
Last edited by TheRealNetherBefore (March 28, 2018 12:17:08)
- deck26
-
1000+ posts
How to make smooth sprite movement + jumping
I suggest you search for ‘platformer tutorial’ and look at the one by @griffpatch_tutor which will tell you all you need about this sort of project.
The problem is that as you fall you accelerate so the amount you move in one step might be enough to go into the ground so you need to code round that. The tutorial will sort you out.
In the meantime here's a remix https://scratch.mit.edu/projects/212977340/ which shows how to better use my script.
The problem is that as you fall you accelerate so the amount you move in one step might be enough to go into the ground so you need to code round that. The tutorial will sort you out.
In the meantime here's a remix https://scratch.mit.edu/projects/212977340/ which shows how to better use my script.
- TheRealNetherBefore
-
1000+ posts
How to make smooth sprite movement + jumping
Ok, I'll check out that tutorial. Thank you! -snip-
- cs3319688
-
3 posts
How to make smooth sprite movement + jumping
how do you make it so the guy jumps and moves at the same time
- Waldi26
-
8 posts
How to make smooth sprite movement + jumping
Last edited by Waldi26 (July 27, 2020 11:11:03)
- Waldi26
-
8 posts
How to make smooth sprite movement + jumping
right arrow statement comes after left and right arrow is 10 by x and left arrow -10 by x
- Discussion Forums
- » Help with Scripts
-
» How to make smooth sprite movement + jumping