So I have tried making 2 cooldowns for a character 1 for cooldown activation of the flight and 2 to send him back right to the ground, what it does it ignores the astart(activation cooldown) and astop(to put the character on the ground) here the code
local gravity = -20
local jump_takeoff_speed = 900
local astart = 4
local astop = 10
local function flight(self)
if self.action == true then
if now > (self.astart + astart) then
gravity = 0
go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, 399.1721, go.EASING_LINEAR, 1)
if now > (self.astop + astop) then
gravity = -20
self.action = false
end
end
end
end
function init(self)
msg.post(".", "acquire_input_focus")
self.position = go.get_position()
local orgp = go.get_position()
self.lives = go.get("#", "lives")
self.astart = 0
self.astop = 0
msg.post("#", "reset")
end
function update(self, dt)
local gravity = vmath.vector3(0, gravity, 0)
self.position = go.get_position()
if not self.ground_contact then
self.velocity = self.velocity + gravity
end
go.set_position(go.get_position() + self.velocity * dt)
self.correction = vmath.vector3()
self.ground_contact = false
flight(self)
end
function on_input(self, action_id, action)
if action_id == hash("jump")then
jump(self)
elseif action_id == hash("action") then
now = socket.gettime()
self.action = true
end
end
Ok so I have removed the delay from the input but it still delaying the output
elseif action_id == hash("action") then
self.action = true
end
local function flight(self)
if self.action == true then
gravity = 0
go.animate(".", "position.y", go.PLAYBACK_ONCE_FORWARD, 399.1721, go.EASING_LINEAR, 1)
timer.delay(4, false, function(self,id)
gravity = -20
self.action = false
end)
end
end
(Update)Ok so it looks like it delaying the flight to 4 seconds like for enabling the gravity, but why?
function on_input(self, action_id, action)
if action_id == hash("jump") then
jump(self)
elseif action_id == hash("action") and not self.action_cooldown then
self.action = true
self.action_cooldown = true
timer.delay(10, false, function(self, id)
self.action_cooldown = false
end)
end
end