Hi there. I just downloaded this game engine and I’m having some trouble with the War Battles tutorial, and I wanted to see if I was doing something wrong. I got to the point in the tutorial which you program the rockets firing but I cannot get them to fire. Take a look at the code and see if there are any issues I am not seeing. Thanks
function init(self)
msg.post(".", "acquire_input_focus")
self.moving = false
self.firing = false -- [1]
self.input = vmath.vector3()
self.dir = vmath.vector3(0, 1, 0)
self.speed = 50
end
function final(self) -- [7]
msg.post(".", "release_input_focus") -- [8]
end
function update(self, dt)
if self.moving then
local pos = go.get_position()
pos = pos + self.dir * self.speed * dt
go.set_position(pos)
end
if self.firing then
factory.create("#rocketfactory") -- [1]
end
self.input.x = 0
self.input.y = 0
self.moving = false
self.firing = false -- [2]
end
function on_input(self, action_id, action) -- [14]
if action_id == hash("up") then
self.input.y = 1 -- [15]
elseif action_id == hash("down") then
self.input.y = -1
elseif action_id == hash("left") then
self.input.x = -1
elseif action_id == hash("right") then
self.input.x = 1
elseif action_id == hash("fire") and action.pressed then
self.firing = true
end
if vmath.length(self.input) > 0 then
self.moving = true -- [16]
self.dir = vmath.normalize(self.input) -- [17]
end
end
function on_reload(self)
-- Add reload-handling code here
-- Remove this function if not needed
end