Making a space shooter, need help with projectiles

Hi! I’m a student in Stockholm and I’m currently working on creating a space shooter in defold.
Currently, the bullets spawn from the ship, but don’t move upwards along the Y axel. Haven’t been able to figure out why yet :stuck_out_tongue:
My bullet class looks like this:

go.property("speed", 700)
local Bullet_1 max_speed = 500

function init(self)
    self.position=go.get_position()
    self.velocity=vmath.vector3(0,1,0)
    self.movement_y = 1
end

function final(self)
--some particle stuff later
end

function update(self, dt)
	self.position=self.position+self.velocity*self.speed*dt
	--Bullet_1_movement(self, dt)
   	go.set_position(self.position)
end

--function Bullet_1_movement(self, dt)
	--local b_pos = go.get_position()
	--self.velocity = vmath.vector3(0, self.movement_y*max_speed,0)
	--go.set_position(go.get_position() + self.velocity * dt)
--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)
    -- Add input-handling code here
    -- Remove this function if not needed
end

function on_reload(self)
    -- Add reload-handling code here
    -- Remove this function if not needed
end

And the firing part of my player class looks like so:

--Projectile properties
go.property("Bullet_1_speed",0.4)
local spawned_objects = {}
local boolean b1 = true


function init(self)
    --msg.post(".", "acquire_input_focus")
	init_vars(self)
end

function init_vars(self)
	msg.post(".","acquire_input_focus")
	self.position = go.get_position()
	self.last_shot=0
	self.speed = 0
    self.velocity = vmath.vector3(0, 0, 0)
    self.movement_x = 0
	self.movement_y = 0 
end

function fire_p1(self, dt)
		self.last_shot=0
		local bullet_1_position = go.get_position
    	bullet_1_position=vmath.vector3(self.position)
    	bullet_1_position.y=bullet_1_position.y*1,5
    	local Bullet_1 = factory.create("#Bullet_1_factory", bullet_1_position, nil, {}, 1)
    	table.insert(spawned_objects,Bullet_1)
    end

Any help would be greatly appreciated :wink:

In the first script, print the different values in the update:

print(self.velocity, self.speed, dt)

Either the script does not run at all (not added to the game object in question), or one of the values is 0.

1 Like