Check if two collision objects are touching in an "if" statement?

Hi, I want to tell if two objects are colliding. I know of:

function on_message(self, message_id, message, sender)
	if message_id == hash("collision_response") then
		--code
	end
end

but I want to be able to tell if two objects are colliding with an if statement, like this:

if x.colliding_with(y) then
	--hypothetical code
end

Is this possible? Thanks for any reponse!

You could track the objects that have sent the ‘contact_point_response’ message in a self object on X, and remove them when the release message is received?

That is a good idea, and was gonna do that, except I can’t seem to find a message for collision released? How would I tell if something is no longer touching something else?

Never mind, here is my solution:

function update(self, dt)
	if self.Touching == hash("geometry") then
		print("what up")
	end

	self.Touching = nil
end

function on_message(self, message_id, message, sender)
	if message_id == hash("collision_response") then
		self.Touching = message.other_group
	end
end
1 Like

You should use a trigger collision object. It will tell you when two objects start to overlap and when they no longer do.

3 Likes

This is a good way of doing it. If you use dynamic physics you can add a separate collision object to deal with those, attached to the same game object.