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

#1 2012-03-14 11:09:45

MP-R
New Scratcher
Registered: 2012-03-09
Posts: 14

Gravity Help!!!!

How do you make gravity on Scratch? I have no clue how to do it!! Please help!!

Is it like:.......?

When green flag clicked
if touching...
  change y by 2
else
  change y by -1

Thankyou!! (it is for school!)

Offline

 

#2 2012-03-14 11:13:15

joletole
Scratcher
Registered: 2011-02-20
Posts: 1000+

Re: Gravity Help!!!!

This belongs in Help with Scripts. I will ask a Scratch Team member to move.

Offline

 

#3 2012-03-14 11:30:46

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Gravity Help!!!!

@your post: Yes, it is to a low level; but a more technically accurate way is:
forever
if touching...
set [yvel v] to (1)
else
change [yvel v] by (-1)
end if
change y by (yvel)

Foar acceleration due to gravity.  wink

EDIT: Don't forget to put it in a forever block. That's important.  smile

Last edited by Hardmath123 (2012-03-14 11:31:19)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#4 2012-03-14 11:54:44

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Gravity Help!!!!

Hardmath123 wrote:

@your post: Yes, it is to a low level; but a more technically accurate way is:

forever
if <touching [ground v]?>
set [yvel v] to (1)
else
change [yvel v] by (-1)
end
change y by (yvel)
Foar acceleration due to gravity.  wink

EDIT: Don't forget to put it in a forever block. That's important.  smile

I made it scratchblocks. For better clarity.
To make it more realistic; (I came up with this myself - I'd appreciate some credit  tongue )

change [yvel v] by (([0] - ((Gravity) / [20])) * (Weight)) //Gravity being the 
//strength for the gravity. 10 is Earth-like
If you have no clue what I'm on about, see the gravity in this

Last edited by Splodgey (2012-03-14 11:55:47)

Offline

 

#5 2012-03-14 17:02:36

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

Re: Gravity Help!!!!

Splodgey wrote:

I made it scratchblocks. For better clarity.
To make it more realistic; (I came up with this myself - I'd appreciate some credit  tongue )

change [yvel v] by (([0] - ((Gravity) / [20])) * (Weight)) //Gravity being the 
//strength for the gravity. 10 is Earth-like

Weight doesn't effect gravitational acceleration.   wink

change [y-vel v] by ((-1) * (gravitational constant))

Last edited by MoreGamesNow (2012-03-14 17:03:59)


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

Offline

 

#6 2012-03-15 04:46:53

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Gravity Help!!!!

MoreGamesNow wrote:

Splodgey wrote:

I made it scratchblocks. For better clarity.
To make it more realistic; (I came up with this myself - I'd appreciate some credit  tongue )

change [yvel v] by (([0] - ((Gravity) / [20])) * (Weight)) //Gravity being the 
//strength for the gravity. 10 is Earth-like

Weight doesn't effect gravitational acceleration.   wink

change [y-vel v] by ((-1) * (gravitational constant))

Unless you're talking about something as big as the moon, but if your project had the moon falling, you already have other physics problem (orbit? collisions? elasticity?).


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#7 2012-03-15 11:56:49

Splodgey
Scratcher
Registered: 2011-04-26
Posts: 500+

Re: Gravity Help!!!!

MoreGamesNow wrote:

Splodgey wrote:

I made it scratchblocks. For better clarity.
To make it more realistic; (I came up with this myself - I'd appreciate some credit  tongue )

change [yvel v] by (([0] - ((Gravity) / [20])) * (Weight)) //Gravity being the 
//strength for the gravity. 10 is Earth-like

Weight doesn't effect gravitational acceleration.   wink

change [y-vel v] by ((-1) * (gravitational constant))

So? I still works better.  hmm  Well, a bit better.

I've been working on something more realistic. Hasn't been going well.

Last edited by Splodgey (2012-03-15 12:01:49)

Offline

 

#8 2012-03-17 09:39:10

JDProducers
Scratcher
Registered: 2011-12-17
Posts: 40

Re: Gravity Help!!!!

well to make realistic gravity you can use the variables option. Just say
IF GREEN FLAG CLICKED
FOREVER
CHANGE Y BY YVEL.(just make a variable labeled xvel and yvel.)

IF GREEN FLAG CLICKED
FOREVER
SET YVEL. TO YVEL. MULTIPLIED BY .91

IF GREEN FLAG CLICKED
FOREVER
IF TOUCHING THIS
SET YVEL. TO 0
IF UP ARROW KEY PRESSED
CHANGE YVEL. BY 5
ELSE
SET YVEL. TO -0.5

you can use this.
The one's on the top will make you character change y position
the bottom one will make sure it doesn't go through the ground.
smile


[img]C:\Documents and Settings\Administrator\My Documents\JDProducers Logo.BMP[/img]

Offline

 

#9 2012-03-17 20:23:13

AgentRoop
Scratcher
Registered: 2012-02-11
Posts: 1000+

Re: Gravity Help!!!!

this is what i always do for gravity:

when gf clicked
forever
  if <touching [ground]>
    set [y velocity] to (0)
  else
    change [y velocity] by (-1)
  end
end
this will apply gravity, then, of course, do this:

when gf clicked
change y by (y velocity)
then, if you want to jump or something, make sure you set y velocity to a certain number (and make sure that it's positive)  wink

I hope this helps and I always use it because it's nice and simple.  smile


La La
I wrote an album.

Offline

 

#10 2012-03-17 20:31:09

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

Re: Gravity Help!!!!

AgentRoop wrote:

this is what i always do for gravity:

when gf clicked
forever
  if <touching [ground]?>
    set [y velocity v] to (0)
  else
    change [y velocity v] by (-1)
  end
end
this will apply gravity, then, of course, do this:

when gf clicked
change y by (y velocity)
then, if you want to jump or something, make sure you set y velocity to a certain number (and make sure that it's positive)  wink

I hope this helps and I always use it because it's nice and simple.  smile

Fixed it a bit  smile

JDProducers wrote:

well to make realistic gravity you can use the variables option. Just say

when gf clicked
forever
change y by <yvel>
when gf clicked
forever 
set [yvel v] to <<yvel>*[0.91]>
when gf clicked
forever
if <touching [ground v]?>
set [yvel v] to [0] 
end
if <key [up arrow v] pressed?>
change [yvel v] by [5]
else
set [yvel v] to [-0.5]
end
you can use this.
The one's on the top will make you character change y position
the bottom one will make sure it doesn't go through the ground.

Fixed this one too!  smile

Offline

 

#11 2012-03-17 20:33:38

AgentRoop
Scratcher
Registered: 2012-02-11
Posts: 1000+

Re: Gravity Help!!!!

AgentRoop wrote:

this is what i always do for gravity:

when gf clicked
forever
  if <touching: [ground]> // this block will be found in the sensing section
    set (y velocity) to (0) // you'll have to make this a variable
  else
    change (y velocity) by (-1)
  end
end
this will apply gravity, then, of course, do this:

when gf clicked
forever
  change y by (y velocity)
end
then, if you want to jump or something, make sure you set y velocity to a certain number (and make sure that it's positive)  wink

I hope this helps and I always use it because it's nice and simple.  smile

sorry, i typed that wrong.
Now it should work.  smile

Also, if you want to jump, do this:

when i receive [jump]
  if <touching: [ground]>
  set (y velocity) to (5)  // you don't have to make it 5, you can make it whatever you want, depending on how high you want to jump.
end
I really hope that this helps you.  big_smile

_____________________________________________________________
I'm trying to think of something clever, funny, or inspiring in my signuature, but i cant think of anything.

-AgentRoop


La La
I wrote an album.

Offline

 

#12 2012-03-17 20:38:43

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

Re: Gravity Help!!!!

@Splodgey

The equation for the force of gravity is this:

Code:

F = G (mass_1 * mass_2) / (distance^2)

and

Code:

F = mass * acceleration

two of the masses cancel, resulting in:

Code:

acceleration = G * mass_1 / (distance^2)

So the acceleration of something falling towards earth is "G*(mass of earth)/( (distance from earth)^2).  "G" is just a constant, so acceleration is only based on the mass of the earth and the distance (basically "mass/(distance*distance)").  Admittedly, the Earth does accelerate towards you (at an acceleration based on your mass), but this is, in my opinion, negligible.  If you want to include the acceleration of the "world" towards you, and calculate an overall velocity, use this:

Code:

(G/(distance^2))((mass of earth)+(mass of you))

That should be it anyway  hmm

Edit: the acceleration caused by you on the earth may not be enough to counter act what little friction there is on earth.  But that's just speculation on my part.

Edit (again): I just realized how appropriate my current quote is to this topic  big_smile

Last edited by MoreGamesNow (2012-03-17 20:49:03)


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

Offline

 

#13 2012-03-18 01:53:10

chanmanpartyman
Scratcher
Registered: 2011-05-30
Posts: 500+

Re: Gravity Help!!!!

http://scratch.mit.edu/forums/viewtopic … 8#p1174788 I added a gravity script that is very efficient.

Offline

 

Board footer