[War Battles Tutorial] Issues relating to RocketsFactory


#1

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 :slight_smile:


#2

Hi!

I quickly went through the tutorial up to that point and works as it should for me. It would be easier to see what is wrong if we had access to your whole setup. I assume everything is in the “main” folder so could you zip it and upload it for us to take a look? :slight_smile:


#3

When things pop in/out of view or never appears chances are that you have stuff on the same or wrong Z coordinate. Check those for your components (sprites) and game
objects.