Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need help with moving x and y at the same time.
- ArtovonGd
-
Scratcher
7 posts
Need help with moving x and y at the same time.
for some reason when i try to move right or left while jumping, it doesn't work, for example. if i press the right arrow key and press the up one at the same time, it forces the player to just jump up, doesn't let it move right.
here is the project: https://scratch.mit.edu/projects/861323369/
please help!
here is the project: https://scratch.mit.edu/projects/861323369/
please help!
- deck26
-
Scratcher
1000+ posts
Need help with moving x and y at the same time.
Your up-arrow key detection has a repeat until not up-arrow pressed loop so none of the other blocks in the forever loop will run until that loop releases control. If you use velocity for movement a jump just sets the y velocity to a positive value (probably only if actually touching ‘ground’ at the time) and your loop just needs to adjust x and y velocity rather than, for example, the right arrow key directly changing x.
So you might set x velocity to 10 when right arrow is pressed or -10 when left arrow is pressed and each time through the loop, if no left/right is pressed you set x-velocity to xvelocity * 0.9 and you change x by x-velocity so your sprie doesn't stop because you've released the key but slows down gradually. For y velocity you would normally subtract a positive gravity value each time through the loop so you decelerate as you rise but accelerate when falling.
So you might set x velocity to 10 when right arrow is pressed or -10 when left arrow is pressed and each time through the loop, if no left/right is pressed you set x-velocity to xvelocity * 0.9 and you change x by x-velocity so your sprie doesn't stop because you've released the key but slows down gradually. For y velocity you would normally subtract a positive gravity value each time through the loop so you decelerate as you rise but accelerate when falling.
- Discussion Forums
- » Help with Scripts
-
» Need help with moving x and y at the same time.