Trigger collision appears to broadcast message (SOLVED)

I have some behaviour that is being triggered at weird times and I don’t understand why.

I saw that… “When two objects collide, the engine will broadcast messages to all components in both objects:” but I believe that the messages are going to other game objects as well.

I have a GO called “x box” with a collision shape, type trigger, group “clickable”. When it receives a trigger collision from “clicker” it prints some text to the console. That’s all fine.

However, the same text is printed when another GO’s collision polygon (in the group “roller”) collides with another GO’s collision polygon (which is also in the group “clickable”).

I realise that it’s a very difficult thing to explain but if anyone has any idea why this might happen I’d be grateful. I only have three scripts running in that collection and none of them explain why this occurs.

Could you please post your scripts and setup?

  • Only one collection is loaded
  • This is the script that is triggered within the gameobject “x box”:
go.property("paused", false)

function on_message(self, message_id, message, sender)
if message_id == hash("trigger_response") and message.group == hash("clicker") then 
print("X CLICKED")
msg.post("brain#script", "release_input_focus") -- stops movement
msg.post("/gamemenu#script", "menuenabled") -- makes menu appear
elseif message_id == hash("trigger_response") and message.group == hash("roller") and message.enter then 
print("X rollED")
elseif message_id == hash("trigger_response") and message.group == hash("roller") and not message.enter then 
print("X UNrollED")
end

function init(self)
end
end

-This is the script in the gamemenu object.

function init(self)
go.set("#sprite", "tint.w", 0)
end

function on_message(self, message_id, message, sender)
print("menuenabled")
go.set(".", "position.x", 500)
go.animate("#sprite", "tint.w", go.PLAYBACK_ONCE_FORWARD, 1, go.EASING_INOUTSINE, 0.2)
go.animate(".", "position.x", go.PLAYBACK_ONCE_FORWARD, 600, go.EASING_INOUTSINE, 0.2)
end

script in the roller object:

function init(self)
print("acquired")
msg.post(".", "acquire_input_focus")
cameraposition = vmath.vector3(0, 0, 0)
end

function on_input(self, action_id, action)
--this moves the collider
	go.set_position(vmath.vector3(action.x, action.y, 0))
--this creates the clicker
	if action_id == hash("click") and action.pressed then
	local p=(vmath.vector3(action.x, action.y, 0))
	factory.create("#clickerfactory", p+cameraposition)
	print("got clicked")
		end
end
  • script in the clicker object
local clicktime= 0
function update(self, dt)
if clicktime<3 then
go.delete(".")
end
end

Just to be clear: a collision between the roller and the gamemenu object triggers the behaviour in the gameobject x box´s script.

Would it be easier to add you as a collaborator on the project?

Yes. Add mikael@sicher.org and I’ll have a look tomorrow.

Thank you.

All of the action takes place in the collection that is called 1. It’s a very small and simple collection so it should be relatively easy to find out what is happening. I should probably warn you now that in order to make programming more exciting, I sometimes put swear words in console messages that I send to myself.

I’ll add you now

2 Likes

I’ll brace myself!! :slight_smile:

Okay, I have damn hell ass sorted this myself. It was a misunderstanding of how collisions worked on my part. Thanks for your offer of help, sicher!

My next question is: When there is a game object with two collisions polygon, is there a way of telling that game object which collision vector registered the collision? i.e not sending the message.group == hash to the other object, but sending it to itself?

edit: put them inside two seperate game objects, sorted it