Detect trigger collisions "on stay" (SOLVED)

Hi everyone,

I’m trying to make a simple game where I need to detect if two objects (a player and a laser) are in the same position at the same time.
The laser has a status to detect if it’s shooting in that moment or not. In that case, I send a message to the player.
The two objects have a trigger collider. The problem is that I can only detect the moment when one collider enters in (or exits from) the other one, but I can not know if the two objects are in the same position and the status of the laser changes in the meantime.

This is the code that I’m using at the moment:


function on_message(self, message_id, message, sender)
	if message_id == hash("trigger_response") then
	    if message.enter and self.is_shooting == true then
    		msg.post("player#controller", "laser_hit")
    	end
    end
end

Is there a way to detect if two objects trigger during each frame? In other engines the function is usually called “on trigger stay”.

Thanks in advance! :slight_smile:

When you change one of your trigger-colliders to either dynamic or kinematic, you can use “contact_point_response” instead of “trigger_response” which should do exactly what you need. My lasers are working like a charm this way.

1 Like

Thanks for the fast reply!
I’m probably doing something wrong, but the object never receives the contact_point_response message (if I try to print something, nothing is shown). Any idea?

function on_message(self, message_id, message, sender)
	if message_id == hash("contact_point_response") then
	    print("contact_point_response was received") -- not printed
	    if self.is_hitting == true then
    		msg.post("player#controller", "laser_hit")
    	end
    end
end

Hello,

I believe that what @Daggett is saying is that you need to change the type of collider, from trigger to kinematic, then you will receive the contact_point_response message

4 Likes

Just to be sure: Have you changed one of your colliders to dynamic or kinematic or are both still triggers? You can also try to change both just for testing this.

2 Likes

Whoops, I misread the original message, confusing kinematic with trigger :sweat_smile:

Now it works - thanks a lot, guys!

1 Like