Failing to go through War Battles tutorial (SOLVED)

im trying to do the “War battles” tutorial and i can’t get the rocket’s shooting although i i have gone through the tutorial several times
here’s my script for player movement i think that i messed up something there

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() 
		pos = pos + self.dir * self.speed * dt 
		go.set_position(pos) 
	end

	if self.firing then
		local angle = math.atan2(self.dir.y, self.dir.x) 
		local rot = vmath.quat_rotation_z(angle) 
		local props = { dir = self.dir } 
		factory.create("#rocketfactory", nil, rot, props) 
	end
	
	self.input.x = 0 
	self.input.y = 0
	self.moving = false
	self.firing = false
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

	if vmath.length(self.input) > 0 then
		self.moving = true 
		self.dir = vmath.normalize(self.input) 
	end
end

any advice would be appreciated

I don’t see any obvious problem. Do you see any errors in the console?

What if you add a print statement in the on_input function where you set self.firing to true? And in update where you check the same value?

At what Z is the sprite in the rocket go?

I have the same problem, the rocket will never be created.

Ok, first thing’s first: do you see any errors in the console? Next: check the z-value of the rocket game object and the sprite. Could they be outside the default -1 to 1 range or below the tilemap?

Hi, thank you for reply
THis is Rocket setting.


Factory setting:

Actually, I tried disable title map, but the rocket still didn’t appear.
There are no error in the console, too.

What position do you pass to factory.create()?

It is in update() function:

function update(self, dt)
	-- Add update code here
	-- Remove this function if not needed
	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	
		local angle = math.atan2(self.dir.y, self.dir.x)
		local rot = vmath.quat_rotation_z(angle)
		local props = {dir = self.dir}
		factory.create("#rocketfactory", nil, rot, props)
	end
	
	self.input.x = 0
	self.input.y = 0
	self.moving = false
	self.firing = false
end

If you put a print() statement right next to factory.create(), do you see the print in the console when you press fire?

I don’t know the reason, but after I delete rocket go and recreate it from scratch, then it worked, thanks everyone.

One thing to keep in mind here is that the second argument is the position and when you pass in nil the spawned object will get the same position as the game object with the factory. That combined with the rocket sprite having a position of 0.8 in your first screenshot could mean that you end up outside the -1 to 1 range (can be changed using a custom render script) and thus not see the rocket.