From 14195dac1eda9140192ca07003258715b8b0abd3 Mon Sep 17 00:00:00 2001 From: sanine Date: Wed, 10 May 2023 23:59:04 -0500 Subject: implement basic floating-ray character controller --- scripts/capsuleMove.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'scripts/capsuleMove.lua') 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 -- cgit v1.2.1