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

#1 2012-09-02 23:12:54

Harmione
New Scratcher
Registered: 2012-08-21
Posts: 11

How to make a sprite "jump"?

If I am making a "run and jump" game, and I want to make a sprite "jump" by hitting the up arrow key, how would I make that code?

Offline

 

#2 2012-09-02 23:19:50

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: How to make a sprite "jump"?

Create a variable named yVelocity.  Add this script to your program:

when gf clicked
forever
if  < key [up arrow v] pressed? >
set [yVelocity v] to [4] // choose a value for the height of the jump
wait until <not<key [up arrow v] pressed?>>
end
end

when gf clicked
forever
change y by (yVelocity)
change [yVelocity v] by (-0.3) // choose a value for the strength of gravity
if <touching [ground v]?>
change y by ((-1) * (yVelocity))
set [yVelocity v] to [0]
end
end

Last edited by amcerbu (2012-09-02 23:21:11)

Offline

 

#3 2012-09-02 23:22:05

Harmione
New Scratcher
Registered: 2012-08-21
Posts: 11

Re: How to make a sprite "jump"?

Thank you so very much. Your help means a lot.

Offline

 

#4 2012-09-02 23:24:07

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make a sprite "jump"?

amcerbu wrote:

Create a variable named yVelocity.  Add this script to your program:

when gf clicked
forever
if  << key [up arrow v] pressed? > and <touching [ground v]?>>
set [yVelocity v] to [4] // choose a value for the height of the jump
wait until <not<key [up arrow v] pressed?>>
end

when gf clicked
forever
change y by (yVelocity)
change [yVelocity v] by (-0.3) // choose a value for the strength of gravity
if <touching [ground v]?>
change y by ((-1) * (yVelocity))
set [yVelocity v] to [0]
end

Added a conditional to prevent a glitch. I also fixed your forever loops.

Last edited by ErnieParke (2012-09-02 23:25:04)


http://i46.tinypic.com/35ismmc.png

Offline

 

#5 2012-09-02 23:26:31

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: How to make a sprite "jump"?

^^ Yeah, thanks.  That was a stupid mistake.

Offline

 

#6 2012-09-03 06:35:56

martajudoka
New Scratcher
Registered: 2012-09-03
Posts: 2

Re: How to make a sprite "jump"?

hola
estaba haciendo un juego y cuando lo he terminado y lo he revisado al cambiar de personaje se me cambiaba aleatoriamente.
AYUDADMEEEEE!!!!!

Offline

 

#7 2012-09-03 07:07:20

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: How to make a sprite "jump"?

martajudoka wrote:

hola
estaba haciendo un juego y cuando lo he terminado y lo he revisado al cambiar de personaje se me cambiaba aleatoriamente.
AYUDADMEEEEE!!!!!

...?

This is the translated version from Google Translate:

Hello, I was making a game and when I'm done and have discussed the change of character is randomly changed me. [removed as it is some unknown text.]!!


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#8 2012-09-03 07:38:17

chongyian
Scratcher
Registered: 2012-05-08
Posts: 1000+

Re: How to make a sprite "jump"?

lol.

Offline

 

#9 2012-09-03 08:42:04

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: How to make a sprite "jump"?

jontmy00 wrote:

martajudoka wrote:

hola
estaba haciendo un juego y cuando lo he terminado y lo he revisado al cambiar de personaje se me cambiaba aleatoriamente.
AYUDADMEEEEE!!!!!

...?

This is the translated version from Google Translate:

Hello, I was making a game and when I'm done and have discussed the change of character is randomly changed me. [removed as it is some unknown text.]!!

That random text actually means "Help me!!!"

Last edited by ErnieParke (2012-09-03 08:43:47)


http://i46.tinypic.com/35ismmc.png

Offline

 

#10 2012-09-03 09:37:39

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: How to make a sprite "jump"?

ErnieParke wrote:

jontmy00 wrote:

martajudoka wrote:

hola
estaba haciendo un juego y cuando lo he terminado y lo he revisado al cambiar de personaje se me cambiaba aleatoriamente.
AYUDADMEEEEE!!!!!

...?

This is the translated version from Google Translate:

Hello, I was making a game and when I'm done and have discussed the change of character is randomly changed me. [removed as it is some unknown text.]!!

That random text actually means "Help me!!!"

Oh. Anyway, (s)he should have posted it in the Language forums.


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#11 2012-09-03 09:49:31

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: How to make a sprite "jump"?

martajudoka wrote:

hola
estaba haciendo un juego y cuando lo he terminado y lo he revisado al cambiar de personaje se me cambiaba aleatoriamente.
AYUDADMEEEEE!!!!!

Translation: Hello, I was making a game and when I finished I discovered that the character randomly changed. Help me!

(I hope I'm correct)


http://i50.tinypic.com/312u714.jpg

Offline

 

Board footer