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

#1 2013-04-15 12:22:46

Ruso306444
New Scratcher
Registered: 2013-04-15
Posts: 3

How do I get my Sprite to do a simple hop?

I wanna know how to make my sprite hop when I press the space key, please help!

Offline

 

#2 2013-04-15 16:05:41

OverPowered
Scratcher
Registered: 2012-07-27
Posts: 100+

Re: How do I get my Sprite to do a simple hop?

Try this:

when green flag clicked
set [YVelocity# v] to (0)
forever
change y by (YVelocity#)
if <key [space key v] pressed?>
set [YVelocty# v] to (10)
end
if <touching color [ground color]?>
set [YVelocity# v] to (0)
else
change [YVelocity# v] by (-1)
end
This will work, basically, though you will get stuck slightly into the ground.
To prevent this, make the "ground" color 1 pixel thick, and below it, have another color. Add this script at the end of your previous script:
if <touching color [push up color]?>
change y by (1)
end


Newest project: Tunnel TEST ~http://blocks.scratchr.org/API.php?user=OverPowered&amp;action=onlineStatus~ On my mind: Unicameralism

Offline

 

#3 2013-04-15 19:15:38

7734f
Scratcher
Registered: 2010-12-23
Posts: 500+

Re: How do I get my Sprite to do a simple hop?

Ruso306444 wrote:

I wanna know how to make my sprite hop when I press the space key, please help!

OverPowered wrote:

Try this:

when green flag clicked
set [YVelocity# v] to (0)
forever
change y by (YVelocity#)
if <key [space key v] pressed?>
set [YVelocty# v] to (10)
end
if <touching color [ground color]?>
set [YVelocity# v] to (0)
else
change [YVelocity# v] by (-1)
end
This will work, basically, though you will get stuck slightly into the ground.
To prevent this, make the "ground" color 1 pixel thick, and below it, have another color. Add this script at the end of your previous script:
if <touching color [push up color]?>
change y by (1)
end

He said a simple hop  tongue

Try this:

when gf clicked
forever
 if <key [space v] pressed?>
  repeat [10]
   change y by [5]
   wait [0.01] secs
  end
  wait [0.3] secs
  repeat [10]
   change y by [-5]
   wait [0.01] secs
  end
 end
Hope that helped!

With regards
~7734f


http://internetometer.com/image/38992.png   http://i37.tinypic.com/2qixx6c.png

Offline

 

#4 2013-04-15 19:54:11

Hyperbola
Scratcher
Registered: 2013-03-15
Posts: 100+

Re: How do I get my Sprite to do a simple hop?

7734f wrote:

Ruso306444 wrote:

I wanna know how to make my sprite hop when I press the space key, please help!

OverPowered wrote:

Try this:

when green flag clicked
set [YVelocity# v] to (0)
forever
change y by (YVelocity#)
if <key [space key v] pressed?>
set [YVelocty# v] to (10)
end
if <touching color [ground color]?>
set [YVelocity# v] to (0)
else
change [YVelocity# v] by (-1)
end
This will work, basically, though you will get stuck slightly into the ground.
To prevent this, make the "ground" color 1 pixel thick, and below it, have another color. Add this script at the end of your previous script:
if <touching color [push up color]?>
change y by (1)
end

He said a simple hop  tongue

Try this:

when gf clicked
forever
 if <key [space v] pressed?>
  repeat [10]
   change y by [5]
   wait [0.01] secs
  end
  wait [0.3] secs
  repeat [10]
   change y by [-5]
   wait [0.01] secs
  end
 end
Hope that helped!

With regards
~7734f

Even simpler:

when key [space v] pressed
change y by (25)
wait (.5) secs
change y by (-25)

Last edited by Hyperbola (2013-04-15 19:54:59)


Tip of the whatever: Don't post in threads older than 2 weeks unless your post will actually be useful.
It's the last day of 1.4! *cries* (quote from NeilWest, rest by me) by the time you read this it probably will be 2.0  sad

Offline

 

Board footer