tiny-ecs-love-template/systems/velocity.lua

18 lines
679 B
Lua

local world = require("world")
local sqrt = math.sqrt
world:filteredSystem("velocity", { position = T.XyPair, velocity = T.XyPair }, function(e, dt, system)
if sqrt((e.velocity.x * e.velocity.x) + (e.velocity.y * e.velocity.y)) < 2 then
-- velocity = nil
else
e.position.x = e.position.x + (e.velocity.x * dt)
e.position.y = e.position.y + (e.velocity.y * dt)
end
end)
world:filteredSystem("drag", { velocity = T.XyPair, drag = T.number }, function(e, dt, system)
local currentDrag = e.drag * dt
e.velocity.x = e.velocity.x - (e.velocity.x * currentDrag * dt)
e.velocity.y = e.velocity.y - (e.velocity.y * currentDrag * dt)
end)