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 | |
parent | 26bfc10ad0e8a355e9b02946dd31642f49a6ec60 (diff) |
implement basic floating-ray character controller
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/capsuleMove.lua | 18 | ||||
-rw-r--r-- | scripts/character/cameraDistance.lua | 6 | ||||
-rw-r--r-- | scripts/character/collide.lua | 6 | ||||
-rw-r--r-- | scripts/character/spring.lua | 29 |
4 files changed, 58 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 diff --git a/scripts/character/cameraDistance.lua b/scripts/character/cameraDistance.lua new file mode 100644 index 0000000..436b4a3 --- /dev/null +++ b/scripts/character/cameraDistance.lua @@ -0,0 +1,6 @@ +require 'honey.std' + +return function(db, id, data) + local node = db:getComponent(id, "node") + node.matrix:translate(Vec3{0, 0, data.yoffset}) +end diff --git a/scripts/character/collide.lua b/scripts/character/collide.lua new file mode 100644 index 0000000..1ac6cff --- /dev/null +++ b/scripts/character/collide.lua @@ -0,0 +1,6 @@ +require 'honey.std' + +return function(db, self, other, point) + local tbl = ode.ContactGeomTable(point) + print(tbl.pos, tbl.normal, tbl.depth, tbl.g1, tbl.g2) +end diff --git a/scripts/character/spring.lua b/scripts/character/spring.lua new file mode 100644 index 0000000..ed3e878 --- /dev/null +++ b/scripts/character/spring.lua @@ -0,0 +1,29 @@ +require 'honey.std' + + +local values = {} +local sum = 0 +function integral(value) + sum = sum + value + table.insert(values, value) + if #values > 20 then + sum = sum - values[1] + table.remove(values, 1) + end + return sum +end + +local prev = 0 +function derivative(value) + local delta = value - prev + prev = value + return delta +end + +return function(db, self, other, point) + local tbl = ode.ContactGeomTable(point) + local x = tbl.depth - 3.8 + local spring = db:getComponent(self, "spring") + spring.F = math.abs(200 * x) + print("depth", x) +end |