18 lines
544 B
Lua
18 lines
544 B
Lua
local min = math.min
|
|
|
|
World:addEntity({ gravity = -300 })
|
|
|
|
local gravities = filteredSystem("gravities", { gravity = T.number })
|
|
|
|
filteredSystem("changeGravity", { changeGravityTo = T.number }, function(e, _, _)
|
|
for _, ge in pairs(gravities.entities) do
|
|
ge.gravity = e.changeGravityTo
|
|
end
|
|
end)
|
|
|
|
filteredSystem("fall", { velocity = T.XyPair, mass = T.number }, function(e, dt)
|
|
for _, ge in pairs(gravities.entities) do
|
|
e.velocity.y = min(400, e.velocity.y - (ge.gravity * dt * e.mass) - (0.5 * dt * dt))
|
|
end
|
|
end)
|