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:
Foar acceleration due to gravity.foreveriftouchingground ▼?setyvel ▼to1elsechangeyvel ▼by-1change y byyvel![]()
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 )
If you have no clue what I'm on about, see the gravity in thischangeyvel ▼by*0-Gravity/20WeightGravity being thestrength for the gravity. 10 is Earth-like
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)
changeyvel ▼by*0-Gravity/20WeightGravity being thestrength for the gravity. 10 is Earth-like
Weight doesn't effect gravitational acceleration.
changey-vel ▼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)
changeyvel ▼by*0-Gravity/20WeightGravity being thestrength for the gravity. 10 is Earth-likeWeight doesn't effect gravitational acceleration.
changey-vel ▼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)
changeyvel ▼by*0-Gravity/20WeightGravity being thestrength for the gravity. 10 is Earth-likeWeight doesn't effect gravitational acceleration.
changey-vel ▼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:
this will apply gravity, then, of course, do this:whenclicked
foreveriftouchinggroundsety velocityto0elsechangey velocityby-1
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)whenclicked
change y byy velocity
Offline
AgentRoop wrote:
this is what i always do for gravity:
this will apply gravity, then, of course, do this:whenclicked
foreveriftouchingground?sety velocity ▼to0elsechangey velocity ▼by-1then, if you want to jump or something, make sure you set y velocity to a certain number (and make sure that it's positive)whenclicked
change y byy velocity![]()
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
whenclicked
foreverchange y byyvelwhenclicked
foreversetyvel ▼toyvel*0.91you can use this.whenclicked
foreveriftouchingground ▼?setyvel ▼to0ifkeyup arrow ▼pressed?changeyvel ▼by5elsesetyvel ▼to-0.5
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:
this will apply gravity, then, of course, do this:whenclicked
foreveriftouching:groundthis block will be found in the sensing sectionsety velocityto0you'll have to make this a variableelsechangey velocityby-1then, if you want to jump or something, make sure you set y velocity to a certain number (and make sure that it's positive)whenclicked
foreverchange y byy velocity![]()
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:
I really hope that this helps you.when i receivejumpiftouching:groundsety velocityto5you don't have to make it 5, you can make it whatever you want, depending on how high you want to jump.
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