summaryrefslogtreecommitdiff
path: root/scripts/character/spring.lua
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-10 23:59:04 -0500
committersanine <sanine.not@pm.me>2023-05-10 23:59:04 -0500
commit14195dac1eda9140192ca07003258715b8b0abd3 (patch)
treebb4e41153363c791d4a9c7948bc85e0d4f77bc98 /scripts/character/spring.lua
parent26bfc10ad0e8a355e9b02946dd31642f49a6ec60 (diff)
implement basic floating-ray character controller
Diffstat (limited to 'scripts/character/spring.lua')
-rw-r--r--scripts/character/spring.lua29
1 files changed, 29 insertions, 0 deletions
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