| Simple
Gravity
Provided by Adam
Montandon
Andrew posted this message
on the
forum.
Anyone know of any
interesting ways to
incorporate realistic
gravity with lingo?
I'm not talking in 3-D
here, just plain old
shockwave. I've tried
numerous approaches,
but can't seem to get
past simple gravity.
In my experience with
Lingo, it is often a lot
faster and easier to understand
if you make something
that "cuts out"
as much of the physics
as possible, but retains
the feel of a physical
world. Gravity and momentum
can be shown in Shockwave
quite simply by "cheating".
When we are dealing with
momentum, it is best to
think of it as a "force"
pushing our object in
different directions,
so gravity is simply a
momentum that pushes downwards,
and continues to push
downwards no matter what.
Now, momentum can be expressed
as a "positive"
force, e.g., the more
momentum the faster an
object goes, and friction
can be expressed as a
negative force, e.g. the
more friction the slower
an object goes.
Objects also have a terminal
velocity, the speed at
which it cannot get any
faster, think of terminal
velocity as a fixed point
"Top speed".
Now, here's the code.
Copy and paste this code,
and set it as a behaviour,
and drop it onto an object.
property spritenum
property
momentum
property
terminalvelocity
property
incriment
on
beginsprite
me
sprite(spritenum).momentum
= 0.0
end
on
exitframe
if
sprite(spritenum).momentum
< sprite(spritenum).terminalvelocity
- sprite(spritenum).incriment
then
sprite(spritenum).momentum
= sprite(spritenum).momentum
+ sprite(spritenum).incriment
else
sprite(spritenum).momentum
= sprite(spritenum).terminalvelocity
end
if
sprite(spritenum).locv
= sprite(spritenum).locv
+ sprite(spritenum).momentum
end
on
getpropertydescriptionlist
description
= [:]
addprop
description, #terminalvelocity,
[#default:40,
#format:#float,
#comment:"Terminal
Velocity:"]
addprop
description, #incriment,
[#default:0.4,
#format:#float,
#comment:"Gravity
incriment:"]
return
description
end
So, basically what happens
is we fake gravity as
a force that every frame
gets bigger and bigger
until it hits terminal
velocity. I have kept
the code as simple as
possible so that beginners
can get the hang of it.
Try experimenting with
different values to get
different effects. See
if you can add friction
into the equation. Its
quite easy to do.
|