diff options
author | sanine <sanine.not@pm.me> | 2023-05-10 23:59:04 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-10 23:59:04 -0500 |
commit | 14195dac1eda9140192ca07003258715b8b0abd3 (patch) | |
tree | bb4e41153363c791d4a9c7948bc85e0d4f77bc98 /scripts/capsuleMove.lua | |
parent | 26bfc10ad0e8a355e9b02946dd31642f49a6ec60 (diff) |
implement basic floating-ray character controller
Diffstat (limited to 'scripts/capsuleMove.lua')
-rw-r--r-- | scripts/capsuleMove.lua | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/scripts/capsuleMove.lua b/scripts/capsuleMove.lua index e454b06..cfc4c85 100644 --- a/scripts/capsuleMove.lua +++ b/scripts/capsuleMove.lua @@ -6,6 +6,10 @@ return function(entities, id, dt) return glfw.GetKey(window.win, key) == glfw.PRESS end + local float = self.node._child.spring.spring.F + ode.BodyAddForce(self.physics._body, 0, float, 0) + self.node._child.spring.spring.F = 0 + local yaw = math.rad( self.node._child.p .node._child.pivot @@ -28,10 +32,22 @@ return function(entities, id, dt) vel = vel - left end - vel = 1000 * vel:normalize() + vel = 2000 * vel:normalize() x, y, z = ode.BodyGetLinearVel(self.physics._body) if Vec3{x,y,z}:norm2() < 500 then ode.BodyAddForce(self.physics._body, vel[1], vel[2], vel[3]) end + + -- slow down + local horizontalDamping = 100 + local verticalDamping = 5 + ode.BodyAddForce(self.physics._body, + -horizontalDamping*x, + -verticalDamping*y, + -horizontalDamping*z) + + if y < 0.3 and float > 0 then + ode.BodySetLinearVel(self.physics._body, x, 0, z) + end end |