Last active
October 20, 2018 08:18
-
-
Save nothke/c833e3e719572bd24171a6f1fc4825aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- variables | |
suspheight = 10 -- height of suspension | |
springrate = 10 -- spring stiffness | |
damprate = 1 -- damping amount | |
bouncemult = 0 -- bounce when we bottom out, keep between 0-1 | |
velo = 0 -- verticla velocity | |
y = 100 -- distance from bottom of vehicle to ground | |
deltatime = 1/30 -- depending on framerate | |
-- ground is assumed to be at 0 | |
-- in game loop | |
if y < suspheight then | |
target = y + suspheight | |
diff = target - y | |
spring = diff * springrate | |
damp = -velo * damprate | |
velo += (spring + damp) * deltatime | |
end | |
-- velocity update | |
velo -= 1 -- gravity | |
y += velo * deltatime | |
-- clamp so we don't go through ground | |
if y < 0 then | |
velo = -velo * bouncemult | |
value = 0; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment