Hello Defold community,
I’m pretty new here so sorry if the stuff I’m asking may seem trivial or obvious to y’all. I’ve started trying out all the Defold tutorials and everything was great until I hit the War Battles tutorial. In the section relating to “Create a rocket game object” I have followed through the steps until “Spawn rockets”. However, when I hit the “space” key (hashed as “fire” in input_bindings) to fire the rockets, my main player sprite disappears and no rockets are spawned at all. I find it really strange as I have spent a few hours looking through everything and re-doing the entire process but the same issue still persists. No errors in logs as shown as well.
My player.script file:
function init(self) msg.post(".", "acquire_input_focus") self.moving = false self.firing = false self.input = vmath.vector3() self.dir = vmath.vector3(0, 1, 0) self.speed = 50 end function final(self) msg.post(".", "release_input_focus") end function update(self, dt) if self.moving then local pos = go.get_position() go.set_position(pos + (self.dir * self.speed * dt)) end if self.firing then factory.create("#rocketfactory") end self.input = vmath.vector3() self.moving = false self.firing = false end function on_message(self, message_id, message, sender) -- Add message-handling code here -- Remove this function if not needed end function on_input(self, action_id, action) if action_id == hash("up") then self.input.y = 1 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 self.moving = true if self.moving then self.dir = vmath.normalize(self.input) end end function on_reload(self) -- Add reload-handling code here -- Remove this function if not needed end
Other relevant images that may help:
Thank you in advance to anyone who can solve this