Hi, sorry for yet another post. I am new to defold and I don’t have a lot of time to complete my project haha.
I have done some tinkering, and have made a projectile system, and am currently trying to make it fire towards the player’s mouse position. It fires the projectile, but it doesn’t fire it to the mouse position, and it does this weird thing where the direction of motion changes when the player walks around.
Here is the code
function init(self)
-- make sure the script will receive user input
msg.post(".", "acquire_input_focus")
end
function on_input(self, action_id, action)
if action_id == hash("attack") and action.pressed then
local pos = go.get_position()
local mouse_pos = vmath.vector3(action.x, action.y, 0)
local direction = vmath.normalize(mouse_pos - pos)
local distance = 350
local to = pos + direction * distance
local bullet_id = factory.create("#pizzafactory", pos)
go.set(bullet_id, "position", pos)
go.animate(bullet_id, "position", go.PLAYBACK_ONCE_FORWARD, to, go.EASING_LINEAR, distance / 350, 0, function()
go.delete(bullet_id)
end)
end
end
Could it be something to do with the (mouse_pos-pos) line?? Or is it an external error, with gameobject placements etc?