Getting double collisions (SOLVED)

I have been making a game where when you hit cheese, it goes to a random position and the score goes up by 1. Every time the mouse touches the cheese however, the collision happens twice. I am having trouble making it only happen once. Here is the script.

function init(self)
	cheese_score = 0
	msg.post("@system:", "set_update_frequency", {frequency = 60})
end

function on_message(self, message_id, message)
	if message_id == hash("trigger_response") then
		cheese_score = cheese_score + 1
		print(cheese_score)
		go.set_position(vmath.vector3(math.random(1,1280), math.random(1,720), 1))
	end
end

Set self.contacted = true when the first contact on the frame happens then check if it is true to skip the second contact on the frame. Then you can set self.contacted = false at end of your update.

1 Like

Or use

if message_id == hash("trigger_response") then
if message.enter then
--Say cheeese!!
end
end

This will only register the contact whenever Jerry(The mouse) enters the Cheese.

3 Likes

Thank for the help. Now I’m going to name the mouse Jerry.

2 Likes