This belongs in Help with Scripts. I will ask a Scratch Team member to move.
Offline
@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.
EDIT: Don't forget to put it in a forever block. That's important.
Last edited by Hardmath123 (2012-03-14 11:31:19)
Offline
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.
EDIT: Don't forget to put it in a forever block. That's important.
I made it scratchblocks. For better clarity.
To make it more realistic; (I came up with this myself - I'd appreciate some credit )
change [yvel v] by (([0] - ((Gravity) / [20])) * (Weight)) //Gravity being the //strength for the gravity. 10 is Earth-likeIf 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
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 )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.
change [y-vel v] by ((-1) * (gravitational constant))
Last edited by MoreGamesNow (2012-03-14 17:03:59)
Offline
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 )change [yvel v] by (([0] - ((Gravity) / [20])) * (Weight)) //Gravity being the //strength for the gravity. 10 is Earth-likeWeight doesn't effect gravitational acceleration.
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?).
Offline
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 )change [yvel v] by (([0] - ((Gravity) / [20])) * (Weight)) //Gravity being the //strength for the gravity. 10 is Earth-likeWeight doesn't effect gravitational acceleration.
change [y-vel v] by ((-1) * (gravitational constant))
So? I still works better. 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
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.
Offline
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 endthis 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)
Offline
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 endthis 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)
I hope this helps and I always use it because it's nice and simple.
Fixed it a bit
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] endyou 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!
Offline
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 endthis will apply gravity, then, of course, do this:when gf clicked forever change y by (y velocity) endthen, if you want to jump or something, make sure you set y velocity to a certain number (and make sure that it's positive)
I hope this helps and I always use it because it's nice and simple.
sorry, i typed that wrong.
Now it should work.
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. endI really hope that this helps you.
Offline
@Splodgey
The equation for the force of gravity is this:
F = G (mass_1 * mass_2) / (distance^2)
and
F = mass * acceleration
two of the masses cancel, resulting in:
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:
(G/(distance^2))((mass of earth)+(mass of you))
That should be it anyway
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
Last edited by MoreGamesNow (2012-03-17 20:49:03)
Offline
http://scratch.mit.edu/forums/viewtopic … 8#p1174788 I added a gravity script that is very efficient.
Offline