Gravity
Author |
Message |
mitchenerjosh
|
Posted: Tue Oct 02, 2007 6:22 pm Post subject: Gravity |
|
|
I need some help... I was wondering if anyone new anyway to simulate gravity in Turing so that i can move say a square along a path but then it falls off when it reaches then end or something just really simple, I'm thinking of making a program like linerider, if you have any idea's please post.. THANKS!
linerider: http://www.official-linerider.com/play.html |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: Tue Oct 02, 2007 7:06 pm Post subject: RE:Gravity |
|
|
If you're object is moving along the ground, you can say that the force of gravity is just a constant force in the downwards direction. So, you've probably already got x and y coordinates defined for your object. Define vx and vy, the velocities in the x and y direction. Then every time through the loop, subtract some constant amount (application of gravity here) from vy. You'd also have to apply the normal force, which will completely cancel the gravitational force if the object is sitting on a flat object. You might be able to get away with simply not applying the gravity force if the object is sitting on another (horizontal) object. |
|
|
|
|
|
mitchenerjosh
|
Posted: Fri Oct 19, 2007 1:10 pm Post subject: RE:Gravity |
|
|
could you please post some example code for me to test out and understand, i am having trouble with this. |
|
|
|
|
|
Cervantes
|
Posted: Fri Oct 19, 2007 4:35 pm Post subject: Re: Gravity |
|
|
Here's some pseudocode:
code: |
loop
if there_is_nothing_under_you then
vy -= gravity
end if
if right_arrow_pressed then
vx += horiz_accel
end if
if left_arrow_pressed then
vx -= horiz_accel
end if
vx *= 0.99 % This mimics applying friction. It will give you a top speed. If this wasn't here, you could accelerate forever to unbounded speeds
x += vx
y += vy
end loop
|
|
|
|
|
|
|
|
|