Hi! Very simple coding question I hope. Lets say I have a value that controls the amount of force placed on an object in a 2d vector: (like {0, 0} being no force applied, {1, 0} being force applied to left {0, 1} being forced applied downwards and etc.)
Now, overtime I would like these force values to deplete till the value itself reaches zero. Is there any formula/function that will do this with relative ease?
local object = {
x = 0,
y = 0,
force = {0, 0}
}
function update(dt)
object.x = object.x + force[1]
object.y = object.y + force[2]
-- a way to do this with if statements would be
--[[
if force[1] > 0 then
force[1] = math.clamp(force[1] - dt, 0, math.huge)
elseif force[1] < 0 then
force[1] = math.clamp(force[1] + dt, -math.huge, 0)
end
if force[2] > 0 then
force[2] = math.clamp(force[1] - dt, 0, math.huge)
elseif force[2] < 0 then
force[2] = math.clamp(force[1] + dt, -math.huge, 0)
end
--]]
-- but is there a simpler way of doing this?
end