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

#1 2009-07-25 09:13:07

JoeKRox
Scratcher
Registered: 2009-07-25
Posts: 2

Jumping?

Is there any way to make a script so that the sprite jumps, but after a bit gravity takes over and makes the sprite come back down? I do not mean change y by so and so. Please reply. :\

Offline

 

#2 2009-07-25 09:26:37

dav09
Scratcher
Registered: 2009-03-25
Posts: 1000+

Re: Jumping?

if you had maybe 5-6 costumes you could have 3 going up and 3 coming down !you could say
<when[space  ]key pressed>
<wait( 0.1 )secsc>
<switch to costume[ 1
<wait( 0.1 )secsc>
<switch to costume[ 2
<wait( 0.1 )secsc>
<switch to costume[ 3
<wait( 0.1 )secsc>
<switch to costume[ 4
<wait(  0.1)secsc>
<switch to costume[ 5
<wait( 0.1 )secsc>
<switch to costume[ 6

Last edited by dav09 (2009-07-25 09:27:42)

Offline

 

#3 2009-07-26 04:07:22

JoeKRox
Scratcher
Registered: 2009-07-25
Posts: 2

Re: Jumping?

Hmm... but if I did that, would I be able to land on platforms?

Offline

 

#4 2009-07-26 13:18:47

justtestingstickman
Scratcher
Registered: 2009-07-04
Posts: 100+

Re: Jumping?

JoeKRox wrote:

Hmm... but if I did that, would I be able to land on platforms?

If you don't use the change Y, you can't land on platforms. At all.


http://img509.imageshack.us/img509/2126/smalladvert.pnghttp://img175.imageshack.us/img175/8867/advertisementfor3sprite.pnghttp://img696.imageshack.us/img696/6061/failc.png
This signature has too many lines.

Offline

 

#5 2009-07-27 01:52:04

deatheater
Scratcher
Registered: 2008-04-11
Posts: 1000+

Re: Jumping?

make a variable called gravity

<{ gravity }>

and add this script to whatever u want to jump

<when green flag clicked>
<set{ gravity }to( 0
<forever>
<if><touching color[ colour of the ground
<set{ gravity }to( 0
<if><key[ up arrow ]pressed?>
<repeat until><<  <not> <touching color[ colour of the ground >>
<set{ gravity }to( however high u want the person to jump
<change y by( <{ gravity }>
<end>
<end>
<else>
<change{ gravity }by( how high gravity you want (make sure it's a negative number)
<change y by( <{ gravity }>
<end>
<end>

Last edited by deatheater (2009-07-27 04:57:14)

Offline

 

#6 2009-07-27 04:55:22

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: Jumping?

You need a jumping script and a gravity script.
To jump:
<when[ Event triggered... ]key pressed>
<broadcast[ gravity ]]
<repeat until><< <touching[edge]  <or> <touching color[ColourOfPlatforms]  >>
||<change y by( 2 )]
<end>
Now, for the gravity script:
<when I receive[ gravity ]]
<set{ var }to( 0
<repeat until><< <touching[edge]  <or> <touching color[ColourOfPlatforms]  >>
||<change{ var }by( 1
||<move( (( 0 <-> var )) )steps>
<end>
This script produces a proper perabila!
You can also replace a straight-up jump with a vector: just point the sprite in the desired direction, and replace the <change y by( 2 )] block in the jump script to <move( 2 )steps>.
(You can see how the increasing var value produces the non linear decrease rate, following a sheared exponential pattern, needed for a perabila)

Enjoy!


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

Board footer