Near the surface of the earth, acceleration due to gravity
is constant and downward.
What this means in terms of the variables of the
physics model is that yAccel will
be a positive number (downward on the screen), and that
it will not change throughout the animation (remains constant).
onbeginsprite(me) sp = sprite(me.spritenum)
y = sp.locv --initialize
position yVelo = 0--object
starts at rest yGrav = .2--constant
downward end
onexitframe() --acceleration, velocity,
position yAccel = yGrav yVelo = yVelo + yAccel
y = y + yVelo
--check and react to
condition if
y > 450then
yVelo = -yVelo
--set sprite position sp.locv = y end
Surface gravity - source
movie - To restart,
right-click and select "restart"
•How is this demo different than the acceleration
demo?
Reacting to the "floor" (similar to the Checking
for Conditions demo) creates a bouncing ball.
Try giving the ball a horizontal velocity and keeping
it on the stage by either wrapping
the horizontal position or bouncing
it off the sides. Should the gravity affect horizontal acceleration?
Why not? Since surface gravity acts only vertically, it has no effect
on horizontal acceleration (gravity's horizontal component is zero).
Note that the ball is always undergoing acceleration, even
when it is slowing down toward the top of its path. In physics, acceleration
means change in velocity rather than "speeding up."
The statement yAccel=yGrav
makes it appear that acceleration and force are equivalent to each other.
Though this isn't the case, they are closely related. This is explained
further in Mass.