I have a game object with a trigger collider that follows the mouse so I can detect if the mouse is colliding with my player object. Everything is working fine on my Mac, but when I try it on a touch device, the trigger isn’t moved to the touch position until the touch input is received. So I have to touch once to move the collider, then touch again in the same spot to get the trigger to activate.
How could I solve this? (I realize my implementation is probably flawed from the start, I am new to Defold)
Here is my code:
function on_message(self, message_id, message, sender)
if message_id == hash("trigger_response") and message.other_id == hash("/mouse") then
if message.enter == true then
self.is_mouse_colliding = true
else
self.is_mouse_colliding = false
end
end
end
function on_input(self, action_id, action)
go.set("/mouse", "position", vmath.vector3(action.x, action.y, -0.5))
if ((action_id == hash("mouse") and action.pressed == true) or (action_id == hash("touch") and #action.touch > 1)) and self.is_mouse_colliding then
--The rest of my on_input code...
end
end
The problem is self.is_mouse_colliding
is not correct on my first touch.
Thanks in advanced!