summaryrefslogtreecommitdiff
path: root/honey/ecs/collision.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 /honey/ecs/collision.lua
parent26bfc10ad0e8a355e9b02946dd31642f49a6ec60 (diff)
implement basic floating-ray character controller
Diffstat (limited to 'honey/ecs/collision.lua')
-rw-r--r--honey/ecs/collision.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/honey/ecs/collision.lua b/honey/ecs/collision.lua
index 5c0452b..4c8af5b 100644
--- a/honey/ecs/collision.lua
+++ b/honey/ecs/collision.lua
@@ -25,8 +25,12 @@ local function createGeom(self, id, collision)
local d = normal:dot(position)
print(normal, d)
geom = ode.CreatePlane(self.space, normal[1], normal[2], normal[3], d)
+ elseif collision.class == "ray" then
+ geom = ode.CreateRay(self.space, collision.length)
end
+ ode.GeomSetCategoryBits(geom, collision.category or 1)
+ ode.GeomSetCollideBits(geom, collision.collide or 0xffffffff)
ode.GeomSetData(geom, id)
collision._geom = geom
@@ -36,6 +40,15 @@ local function createGeom(self, id, collision)
end)
end
+
+local function isPlaceable(collision)
+ if collision.class == "ray" then
+ return true
+ end
+ return false
+end
+
+
system = function(params)
local db = params.db
local space = params.space
@@ -50,6 +63,28 @@ system = function(params)
createGeom(self, id, collision)
print(id, collision._geom)
end
+ if
+ not self.db:getComponent(id, "physics") and
+ isPlaceable(collision)
+ then
+ -- no attached physics body, update position & orientation
+ -- from node transform
+ local node = self.db:getComponent(id, "node")
+ local m = node._matrix or node.matrix
+ local geom = collision._geom
+ ode.GeomSetPosition(
+ geom,
+ m[1][4],
+ m[2][4],
+ m[3][4]
+ )
+ ode.GeomSetRotation(
+ geom,
+ m[1][1], m[1][2], m[1][3],
+ m[2][1], m[2][2], m[2][3],
+ m[3][1], m[3][2], m[3][3]
+ )
+ end
end
end
}