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

#1 2010-05-09 03:38:13

mikey1105
Scratcher
Registered: 2010-03-22
Posts: 39

A way to set gravity?

Is there a way to set gravity in your project? I don't care what you have to do, nothing is too advanced.

Offline

 

#2 2010-05-09 09:15:54

MaxtheWeirdo
Scratcher
Registered: 2010-03-18
Posts: 500+

Re: A way to set gravity?

A simple forever loop would suffice.


[blocks]
<forever>
<if> <<  <not> <touching color[ x] >>
<change y by( -1)
<end>
<end> [/blocks]
There you go.


My website. Hall Crawler My Awesome OS
It's just marketing, guys! Nothing sinister!

Offline

 

#3 2010-05-09 09:24:26

demosthenes
Retired Community Moderator
Registered: 2008-02-19
Posts: 1000+

Re: A way to set gravity?

I wrote a big tutorial about this, you can check it out here! The important part for you is the first section "Y Velocity", but if you want smooth side-to-side movement check out the second part "X Velocity"


I've taken a long hiatus, but I still visit sometimes. Give me some time to answer any messages you post on my projects!

Offline

 

#4 2010-05-09 16:50:50

DaedalusYoung
Scratcher
Registered: 2010-05-05
Posts: 8

Re: A way to set gravity?

If you want more advanced gravity, make the 'change y by' a little bit higher each loop (until terminal velocity is reached, which could occur if your stage represents an enormous height).
So you would get something like:

yVelocity = 1
if (not touching color x) or (has reached bottom of screen) {
  change y by yVelocity
  yVelocity = yVelocity + 0.1 (or whatever looks good)
  }

(Sorry, I'm not used to working with blocks on the forums as I'm new, and there's no Preview button, so I don't take the risk of screwing up the post  tongue  If you absolutely need blocks, say so)

Offline

 

Board footer