TRIGGER COLLIDER sends message as COLLISION_RESPONSE? (SOLVED)

Hey there.

Got a little problem (maybe bug?)

I have a GO with sprite. I’ve attached 2 collider:
a) a smaller kinematic collider (if something hits the GO)
b) a bigger trigger-collider (kind of radar or if something near GO).

In editor looks like this:

The code who receives the messages is like this:

		-- COLLISION with something?
		if (message_id == GLOBAL.COLLISION_RESPONSE) then --and message_id ~= hash("trigger_response")) and message.other_id ~= go.get_id() then
			print("UNIT COLLIDING : " .. go.get_id())
			print(message_id)
			-- UNIT COLLIDES WHILE SPAWNING move +1 +1
			if message.group == hash("unit") or message.group == hash("structure") then
				if self.inconstruction == true then
					print("UNIT: " .. go.get_id() .. " : Collision while spawning with group " .. message.group .. " otherid " .. message.other_id)
					local newpos = go.get_position() + vmath.vector3(GLOBAL.TILESIZE, GLOBAL.TILESIZE, 0)
					--print("UNITSCRIPT: SPAWN COLLISION at " .. self.unit.mapPosX .."x" .. self.unit.mapPosY)
					go.set_position(newpos)
				else
					print("UNIT: " .. self.unit.name .. " COLLISION with " .. tostring(sender))
					stop_unit(self)
				end
			end
		end
DEBUG:SCRIPT: UNIT COLLIDING : [/instance35]
DEBUG:SCRIPT: hash: [collision_response]

Why does the message_id is COLLISION_RESPONSE (here a global value GLOBAL.COLLISION_RESONSE) if I “trigger” the outer TRIGGER-COLLIDER?

Oh…have to say something important!
At the GO where the TRIGGER-COLLIDER is attached, it works!

But the OTHER GO (which collides) its just a simple COLLISION_RESPONSE. Bug? Missing Feature?
Very bad to handle for the colliding GO

So you have a collision object of type kinematics and one of type trigger and you’re getting both a trigger_response and collision_response?

I think this is the expected behaviour, but I’m not sure.

Hey britzl.

The thing is, the GO which has both colliders are attached receiving the correct messages.

Stange is, the GO who collides with it are not differencing between the two collisions. This GO just receives the collision_response message, but there is no difference if it is a normal kinematic collision or a trigger-collision.

I’m trying to replicate your setup. Can you please confirm if this is the correct setup:

GameObjectA

  • Kinematic object. group = kinematic_a, mask = trigger_b, kinematic_b

GameObjectB

  • Kinematic object. group = kinematic_b, mask = kinematic_a
  • Trigger object. group = trigger_b, mask = kinematic_a

If the above is correct, then what do you believe is the expected behaviour?

Hey britzl.

Not exactly.

Lets clear this out.
The idea behind this is the following:
Having a GameObject (later GO-A) with a kinematic-collider (smaller) for collisions like bullets etc.
Having a second trigger-collider (bigger than the kinematic) as a tigger if another GameObject (like a unit like GO-B) is near the GO-A (base). I’ll use this technique for reloading and healing the unit (GO-B).

Lets say THIS is GameObjectA (in my project its called “structure_base”) with it colliders:

And this is a GameObjectB example (here “unit_buggy”) with its colliders:

Problem/Situation:

GO-B (buggy) moves near the GO-A (base) until first collision (TRIGGER). The GO-A correctly receives a message “trigger_response” BUT the GO-B receives a “collision_response” message. Should it be like this???

How should I know that the GO-B is colliding with a TRIGGER-collider?
Of cause I could send a message from GO-A to GO-B saying “hey you collided with a trigger” but that wont work well (already done) beause the collision messages are faster and the GO-B already collided :frowning:

Ah, ok, I see. I’ve replicated your setup and my unit_buggy gets one trigger_response and then continuously collision_response messages. I believe this is to be expected. Aren’t you seeing a trigger_response on the unit_buggy?

Like I’ve wrote the STRUCTURE_BASE received the TRIGGER hash(“trigger_response”) (and I quess later on if it moves on the KINETIC Collision hash(“collision_response”)) message. Thats ok.

But…
the UNIT just receives a KINETIC-Collision hash(“collision_response”) while it collides with the TRIGGER-COLLIDER!

there is NO result/message at UNIT of hash(“trigger_response”). meaning: colliding with the unit to ANY collider just returns a message of hash(“collision_response”). Shouldn’t that be a trigger_response if it collides with a trigger-collider???

Thats the “base” (GO-A) ingame with physics-debug. You can see the “inner” collider (kinetic) and the “outter”/bigger trigger collider (the grey squares :slight_smile: ) At the botton-right you aready see the buggy.

hm… oh… grr…
not sure why, but now I get a trigger-collision-message at the unit.

maybe because the “old” code was something like:
if trigger then

end

if kinematic then

end

not its like this:

if trigger then

ELSEif kinematic then

end

(first code was from the first lines of code in this project. recoding the statements step by step actually).

output now:

DEBUG:SCRIPT: GAME STARTED
DEBUG:SCRIPT: UNIT KINEMATIC-COLLISSION : [/instance29] group [structure] id [/instance15]
DEBUG:SCRIPT: STRUCTURE: TRIGGER-COLLISION: [/instance15] group [unit], id [/instance29]
DEBUG:SCRIPT:  - enter
DEBUG:SCRIPT: UNIT TRIGGER-COLLISION: .. [/instance29] group: [structure] id [/instance15]
DEBUG:SCRIPT: UNIT KINEMATIC-COLLISSION : [/instance29] group [structure] id [/instance15]
DEBUG:SCRIPT: UNIT KINEMATIC-COLLISSION : [/instance29] group [structure] id [/instance15]
DEBUG:SCRIPT: UNIT KINEMATIC-COLLISSION : [/instance29] group [structure] id [/instance15]

One this is “unclear” now.

Why there is a unit-kinematic-collision before the unit-trigger collision???

here is the code for each Gameobject:

STRUCTURE (GO-A):

		if message_id == hash("trigger_response") then
			print("STRUCTURE: TRIGGER-COLLISION: " .. go.get_id() .. " group " .. message.group ..", id " .. message.other_id)
			-- just entered
			if message.enter and message.group == hash("unit") then
				msg.post(message.other_id, "joinBase")
				print(" - enter")
			else
				msg.post(message.other_id, "leftBase")
				print(" - left")
			end
			return true
		end

UNIT (GO-B):

		-- COLLISION with something?
		if message.group == hash("unit") or message.group == hash("structure") then
			if message_id == hash("trigger_response") then
				print("UNIT TRIGGER-COLLISION: .. "  .. go.get_id().. " group: " .. message.group .. " id " .. message.other_id)

			elseif message_id == GLOBAL.COLLISION_RESPONSE then --and message_id ~= hash("trigger_response")) and message.other_id ~= go.get_id() then
				print("UNIT KINEMATIC-COLLISSION : " .. go.get_id() .. " group " .. message.group .. " id " .. message.other_id)
				-- UNIT COLLIDES WHILE SPAWNING move +1 +1
					if self.inconstruction == true then
						print("UNIT: " .. go.get_id() .. " : Collision while spawning with group " .. message.group .. " otherid " .. message.other_id)
						local newpos = go.get_position() + vmath.vector3(GLOBAL.TILESIZE, GLOBAL.TILESIZE, 0)
						--print("UNITSCRIPT: SPAWN COLLISION at " .. self.unit.mapPosX .."x" .. self.unit.mapPosY)
						go.set_position(newpos)
					end
			end
		end

For my logic the TRIGGER collision should be the first message because its the first contact or not?

There’s a kinematic collision happening because one of your objects is kinematic (the unit_buggy).

Why not have a different group for the trigger, perhaps structure_trigger, and check message.group in unit_buggy? If message.group == hash("structure_trigger") while resolving a collision_response then ignore it.

:slight_smile:
Sure, good idea. And a solution. But I try to use all mechanics of the engine :slight_smile: and trigger sounds good for me :slight_smile:

The problem with the kinematic-before-trigger is: units are stopping if they collide.

but I’ve solved this in another way: raycasts. every unit now has a raycast in driving-direction. Its more “smooth” for stopping.

I’ll mark this topic as solved if you agree

I guess if a beginner will search something similar, he’ll have all answers and code needed to work with if he has similar problems.