I am trying to make an object move randomly. I made a random number generator and want to set a timer to make the number generator generate a number every 1 or 2 seconds. I have it so when i push a key it will generate a number right now. Help?
--elseif love.keyboard.isDown("i") then
--rand = math.random(1, 4)
end
if rand == 1 then
objects.box2.body:applyForce(500, 0 )
elseif rand == 2 then
objects.box2.body:applyForce(-500,0)
elseif rand == 3 then
objects.box2.body:applyForce(0, 500)
elseif rand == 4 then
objects.box2.body:applyForce(0, -500)
end
seconds = 0
timerun = 1
function update_fps(dt)
baseTimer = baseTimer + dt
if baseTimer > 1 then
baseTimer = baseTimer - 1
seconds = seconds + timerun
end
if seconds > 2 then
seconds = 0
end
if seconds >=2 then
rand = math.random(1, 4)
end
end