Trigger message not sent when moving collider to touch position

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!

You need to setup a touch event in the game.input_bindings, then in the update function self will pass the touch event as self.touch.x and self.touch.y, these are your mouse co-ords as well, use these to move the collisionobject to.
Use the group and mask so that when the collision happens it can only be a mouse collision.

function update(self, dt)
local mouse = new vector3(self.touch.x, self.touch.y, 0)
go.set_position(".", mouse)
end

This should help you move in the right direction

Also make sure the init function that contains

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

lastly assign this script to the collision object