your script makes a sprite go right...
If you want a simple jumping script, use this (you might have to adjust it for your game)
when key [space v] pressed if <touching [ground v] ?> repeat (height) change y by (speed) end repeat until <touching [ground v] ?> change y by ((-1)*(speed)) end endIf you want a more realistic gravity jump script use this: (you need a yv variable)
when key [space v] pressed if <touching [ground v] ?> set [yv v] to (15)//or however high you want to jump end
when flag clicked forever if <not<touching [ground v] ?>> change [yv v] by (-1) //or however fast you want it to go down else set [yv v] to (0) end change y by (yv) endHope this helped!
Offline
here is a quick example of realistic gravity jumping:
http://scratch.mit.edu/projects/aryabtsev/2453368
Offline
64no wrote:
Wait:
when [space v] key pressed if <touching color [#FF0000] ?> repeat (height) change y by (speed) end repeat until <touching color [#FF0000]?> change y by <[-1]*(speed)> end end
Scripts fixed by: TorbyFork234
Offline
64no wrote:
wait again:
when [space v] key pressed if <touching color [#EDC88C]?> repeat (height) change y by (speed) end repeat until <touching color [#EDC88C]?> //should that be capital? change y by <(-1) * (speed)> end end
Scripts fixed again by: TorbyFork234
Offline
64no wrote:
Wait:
when [space v] key pressed if <touching color [EDC88C] ?> repeat (height) change y by (speed) end repeat until <touching color [EDC88C]> end end
wrong;
TorbyFork234 wrote:
when [space v] key pressed if <touching color [#FF0000] ?> repeat (height) change y by (speed) end repeat until <touching color [#FF0000]?> change y by <[-1]*(speed)> end endScripts fixed by: [i][color=blue]TorbyFork234
Right.
Offline
Here is how to make your sprite jump up and go down on a flat surface:
when [up arrow v] key pressed change y by (10) change y by (-10)Now how to create a jumping sprite on any kind of a surface:
when [up arrow v] key pressed change y by (10) repeat until <touching color [#18DB2F]?> //This needs to be the color of the ground. change y by (1) end
Last edited by SOScratch (2012-04-08 16:49:12)
Offline
SOScratch wrote:
Here is how to make your sprite jump up and go down on a flat surface:
when [up arrow v] key pressed change y by (10) change y by (-10)Now how to create a jumping sprite on any kind of a surface:when [up arrow v] key pressed change y by (10) repeat until <touching color [#18DB2F]?> //This needs to be the color of the ground. change y by (-1) end[/quote]
Scripts fixed by COOLHOGS
EDIT: Ahh, I messed up the topic...
Offline
In order to do this without variables (which I've found can make things complicated) just do:
when key [up arrow v] pressed glide (1) secs to x (x position) y ((y position) + (10)) repeat until <touching [ground v]> change y by (-2)
Offline
If you use variables, you could do something like this:
when key [up arrow v] pressed set variable [ymax] to (5) change x by (xvel) change y by (yvel) change variable [yvel] by (1) if < (yvel) > (ymax) > set variable [yvel] to (ymax) if key [right arrow v] pressed set variable [xmax] to (5) change x by (xvel) change variable xvel by (1) if < (xvel) > (xmax) > set variable [xvel] to (xmax) end end if < (yvel) = (ymax) > change x by (xvel) change y by (0-(yvel))This will allow you to move to the right while jumping.
Offline
On the sprite that's jumping;
when green flag clicked set (y velocity) to [0] forever if <touching color [#36E813]?>//Change the colour in this block to the colour of the ground. if <key [up arrow v] pressed?> set [y velocity v] to (10) else set [y velocity v] to (1) end else change [y velocity v] by (-1) end change y by (y velocity) end
Offline
aryabtsev wrote:
your script makes a sprite go right...
If you want a simple jumping script, use this (you might have to adjust it for your game)when key [space v] pressed if <touching [ground v] ?> repeat (height) change y by (speed) end repeat until <touching [ground v] ?> change y by ((-1)*(speed)) end endIf you want a more realistic gravity jump script use this: (you need a yv variable)when key [space v] pressed if <touching [ground v] ?> set [yv v] to (15)//or however high you want to jump endwhen flag clicked forever if <not<touching [ground v] ?>> change [yv v] by (-1) //or however fast you want it to go down else set [yv v] to (0) end change y by (yv) endHope this helped!
that doesn't work.
Offline
@mythbusteranimator
Your first script doesn't allow the sprite's x-position to change while it is jumping. I don't think your second script works either.
Anyway, 64no seems to have gotten his/her answer, so it seems that additional solutions aren't really neccessary
However, it you (64no) still need help, here is the wiki article on jumping; it offers scripts of varying complexity (all of which should work).
Offline
Another way to do it would be this. You would have to have a variable "Gravity" set as -5 or some other negative number that controls how fast you fall. The higher the number after the minus, the faster you will fall. Use the "touching color []" block instead of the "touching ground" block. This script makes it so you can't "double jump".
[scratchblocks]
when key space v pressed
forever
if <touching ground v?>
change y by (10)
else
change y by (gravity)
end
[\scratchblocks]
If I did that right you should see a script. If not... sorry.
Unknown164
Offline
when gf clicked forever if <not <touching [ground v] ?>> set [Y volocity v] to [ -1] repeat until <touching [ground v] ?> change Y by (Y volocity) change [Y volocity v] by [0.1] end end
Last edited by ftf841 (2012-05-06 12:23:11)
Offline