This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-04-05 23:21:32

64no
Scratcher
Registered: 2012-02-26
Posts: 8

How to jump and land

I'm wondering how to jump and land.


 when [up v] key  pressed
 change x by [10]
 
is how you do a jump without coming down, right?

Offline

 

#2 2012-04-06 00:12:42

aryabtsev
Scratcher
Registered: 2012-02-05
Posts: 81

Re: How to jump and land

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
end
If 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)
end
Hope this helped!


http://i.imgur.com/NX7AO.jpg

Offline

 

#3 2012-04-06 10:07:37

64no
Scratcher
Registered: 2012-02-26
Posts: 8

Re: How to jump and land

Thanks! smile

Offline

 

#4 2012-04-06 10:30:19

64no
Scratcher
Registered: 2012-02-26
Posts: 8

Re: How to jump and land

Uh, but where do you get ground? sad

Offline

 

#5 2012-04-06 10:36:43

64no
Scratcher
Registered: 2012-02-26
Posts: 8

Re: How to jump and land

oops,this must be it:

when [space v] key pressed
change y by [10]

Offline

 

#6 2012-04-06 10:57:06

pi3
Scratcher
Registered: 2011-12-31
Posts: 500+

Re: How to jump and land

64no wrote:

oops,this must be it:

when [space v] key pressed
change y by [10]

Actually, you want to make it so that where aryabtsev has touching ground, you want touching the color of the ground.


http://i44.tinypic.com/ofdhc4.jpgThanks FreshStudios!

Offline

 

#7 2012-04-07 12:43:15

aryabtsev
Scratcher
Registered: 2012-02-05
Posts: 81

Re: How to jump and land

here is a quick example of realistic gravity jumping:
http://scratch.mit.edu/projects/aryabtsev/2453368


http://i.imgur.com/NX7AO.jpg

Offline

 

#8 2012-04-08 16:27:18

64no
Scratcher
Registered: 2012-02-26
Posts: 8

Re: How to jump and land

Wait:

when [space v] key pressed
if <touching color [EDC88C] ?>
repeat (height)
change y by (speed)
end
repeat until <touching color [EDC88C]>
end
end

Offline

 

#9 2012-04-08 16:35:41

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: How to jump and land

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

 

#10 2012-04-08 16:38:16

64no
Scratcher
Registered: 2012-02-26
Posts: 8

Re: How to jump and land

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

Offline

 

#11 2012-04-08 16:45:49

TorbyFork234
Scratcher
Registered: 2012-03-01
Posts: 1000+

Re: How to jump and land

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

 

#12 2012-04-08 16:47:43

64no
Scratcher
Registered: 2012-02-26
Posts: 8

Re: How to jump and land

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
end
Scripts fixed by: [i][color=blue]TorbyFork234

Right.

Offline

 

#13 2012-04-08 16:47:56

SOScratch
Scratcher
Registered: 2010-02-01
Posts: 100+

Re: How to jump and land

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)


-SOScratch
Scratch On!

Offline

 

#14 2012-04-08 16:53:26

coolhogs
Scratcher
Registered: 2011-07-26
Posts: 1000+

Re: How to jump and land

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...


Get ready for domination of:  tongue

Offline

 

#15 2012-04-09 15:30:15

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: How to jump and land

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)
 


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#16 2012-04-10 10:33:11

mythbusteranimator
Scratcher
Registered: 2012-02-28
Posts: 1000+

Re: How to jump and land

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.


http://www.foxtrot.com/comics/2012-04-01-fdb37077.gif
clicky

Offline

 

#17 2012-04-11 10:14:28

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: How to jump and land

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


Why

Offline

 

#18 2012-04-20 16:34:19

k4den
Scratcher
Registered: 2012-01-25
Posts: 9

Re: How to jump and land

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
end
If 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)
end
Hope this helped!

that doesn't work.

Offline

 

#19 2012-04-20 18:36:37

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to jump and land

@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  hmm

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).  smile


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#20 2012-05-06 12:16:00

Unknown164
Scratcher
Registered: 2012-04-08
Posts: 7

Re: How to jump and land

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

 

#21 2012-05-06 12:21:49

ftf841
Scratcher
Registered: 2012-02-19
Posts: 1000+

Re: How to jump and land

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)


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Hi+there./mca.png
http://mag.racked.eu/mcimage/i354/Achievement++get%21/CAKE%21%21%21%21%21/mca.png

Offline

 

Board footer