# How to check the objectCollision that send message? (SOLVED)

**URL:** <https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975>\
**Category:** Questions\
**Created:** [January 13, 2017, 5:23pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975 "2017-01-13T17:23:08Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhonatanvinicius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonatanvinicius/32/2788_2.png) [@jhonatanvinicius](https://forum.defold.com/u/jhonatanvinicius)\
**Post date:** [January 13, 2017, 5:23pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/1 "2017-01-13T17:23:08Z")

</div>

Hello guys… help me with this question.

My GO has two object colision. one at top another at bottom. when i use pprint to check the sent value I got

```lua
[main:/instance1#collisionobject]

```

so i need to compare the values, I do this:

```lua
if sender == hash(<????>) then ... end

```

in this case which value i need to put in \<????\> to check wich component receive the colission?

---

<div class="post-metadata">

**Author:** ![sicher](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/sicher/32/8_2.png) [@sicher](https://forum.defold.com/u/sicher)\
**Post date:** [January 13, 2017, 5:30pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/2 "2017-01-13T17:30:20Z")

</div>

It is an URL so `if sender.path == hash("/instance1")` should work.

---

<div class="post-metadata">

**Author:** ![jhonatanvinicius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonatanvinicius/32/2788_2.png) [@jhonatanvinicius](https://forum.defold.com/u/jhonatanvinicius)\
**Post date:** [January 13, 2017, 5:46pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/3 "2017-01-13T17:46:52Z")

</div>

but this is the problem…

“/instance1”  
“/instance1”  
“…”  
“/instance10”

is is automatically generated by the factory

how to handle with is?

“/instance??#collisionobjectTOP”  
“/instance??#collisionobjectBOTTOM”

---

<div class="post-metadata">

**Author:** ![Edgaronfo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/edgaronfo/32/18438_2.png) [@Edgaronfo](https://forum.defold.com/u/Edgaronfo)\
**Post date:** [January 13, 2017, 6:23pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/4 "2017-01-13T18:23:15Z")

</div>

Hello @jhonatanvinicius,

Remember that all objects can send and receive messages, so in your case, your player is receiving a collision message in the format that you are describing: “/instance??#collisionobjectTOP”, BUT your other object can also detect the collision and send a message identifying itself, something like (pseudocode):

```lua
other object on_message(...)
  if message == contact_point
     msg(player_url, "I_GOT_YOU", { id = go.get_id() } )

```

And then your player object would have to listen for these messages:

```lua
player object on_message(...)
  if message == "I_GOT_YOU"
     receive_damage_from(message.other_id)

```

OR

Another case would be to use only the ` fragment` portion from the sender (`sender` is an **url** ) so you get the collision that was hit “#collisionobjectTOP” or “#collisionobjectBOTTOM” without taking in consideration who sent it:

```lua
player object on_message(...)
   if message == contact_point
      if sender.fragment == #collisionobjectTOP then
            -- receive top damage
      else if sender.fragment == #collisionobjectBOTTOM then
            -- receive bottom damage
      end

```

Hope this helps

---

<div class="post-metadata">

**Author:** ![jhonatanvinicius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonatanvinicius/32/2788_2.png) [@jhonatanvinicius](https://forum.defold.com/u/jhonatanvinicius)\
**Post date:** [January 13, 2017, 6:34pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/5 "2017-01-13T18:34:43Z")

</div>

> [@Edgaronfo](#):
>
> fragment

wow i believe that now will work. This option(sender.fragment) it is new for me. when at home i will test. thanks.

---

<div class="post-metadata">

**Author:** ![Edgaronfo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/edgaronfo/32/18438_2.png) [@Edgaronfo](https://forum.defold.com/u/Edgaronfo)\
**Post date:** [January 13, 2017, 6:39pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/6 "2017-01-13T18:39:08Z")

</div>

Nice,

You see, **url** ’s have 3 parts: socket, path and fragment.

You can read more about it in the [defold msg.url documentation](http://www.defold.com/ref/msg/#msg.url:urlstring)

---

<div class="post-metadata">

**Author:** ![jhonatanvinicius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonatanvinicius/32/2788_2.png) [@jhonatanvinicius](https://forum.defold.com/u/jhonatanvinicius)\
**Post date:** [January 13, 2017, 8:01pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/7 "2017-01-13T20:01:17Z")

</div>

> [@Edgaronfo](#):
>
> url’s have 3 parts: socket, path and fragment.

i see. but i cant check the right contact object… see the image bellow:

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/9/9d854b90dfa1b6280eb6fd2f94139b8762dbe5cf.png)

here is the contact point:

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/d/d9b11ee51c90049aad78f4c5624b21d3dcfe860e.jpg)

---

<div class="post-metadata">

**Author:** ![Edgaronfo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/edgaronfo/32/18438_2.png) [@Edgaronfo](https://forum.defold.com/u/Edgaronfo)\
**Post date:** [January 13, 2017, 9:22pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/8 "2017-01-13T21:22:15Z")

</div>

Ok,

I think it is pretty easy, you have to do something like (pseudocode):

```lua
player object on_message(...)
   if message_id == contact_point
      if sender = url("footgirl")
          -- receive foot damage here

```

---

<div class="post-metadata">

**Author:** ![Davej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/davej/32/3451_2.png) [@Davej](https://forum.defold.com/u/Davej)\
**Post date:** [January 13, 2017, 10:09pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/9 "2017-01-13T22:09:06Z")

</div>

Might find this helpful too,

```lua
if message_id == hash("contact_point_response") then	-- check if we received a contact point message
	if message.group == hash("foot_girl") then -- check that the object is something we consider geometry
		handle_geometry_contact(self, message.normal, message.distance)
	end
end

```

and change it’s group to foot\_girl

---

<div class="post-metadata">

**Author:** ![Edgaronfo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/edgaronfo/32/18438_2.png) [@Edgaronfo](https://forum.defold.com/u/Edgaronfo)\
**Post date:** [January 13, 2017, 11:37pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/10 "2017-01-13T23:37:30Z")

</div>

Hey @Davej ,

Yours is a good idea too, to use:

```lua
message.group == hash("foot_girl")

```

instead of:

```lua
sender == msg.url("foot_girl")

```

but @jhonatanvinicius would have to change his game objects and collision objects, doesn’t he?

---

<div class="post-metadata">

**Author:** ![jhonatanvinicius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonatanvinicius/32/2788_2.png) [@jhonatanvinicius](https://forum.defold.com/u/jhonatanvinicius)\
**Post date:** [January 14, 2017, 3:28pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/11 "2017-01-14T15:28:59Z")

</div>

HEllo @Edgaronfo and @Davej.

I have tst your hints but didn’t work…

see my test details…

1. in my **dino script** i put this inside message function:

```lua
if message_id == hash("contact_point_response") then

       if message.group == hash("hero") then
	 		pprint("+++++++ begin test")
	 		pprint("footgirl as url: " .. msg.url("footgirl"))
	 		pprint("message sender: " .. sender)
	 		pprint("message id: " .. message_id)
	 		if sender == msg.url("footgirl") then -- check edga hint
	 			print('OK to URL')
	 		
	 		end
	 		
	 		if message.group == hash("footgirl") then -- check dajev hint
	 			print('OK to group')
	 		
	 		end
	 		pprint(" === start message info")
	 			  pprint(message)
	 		pprint(" === end message info")
	 		pprint("+++++++ end test")
      end
end

```

and this is my console response:

```lua
DEBUG:SCRIPT: +++++++ begin test
DEBUG:SCRIPT: footgirl as url: [main:/footgirl]
DEBUG:SCRIPT: message sender: [main:/instance1#collisionobject]
DEBUG:SCRIPT: message id: [contact_point_response]
DEBUG:SCRIPT: === start message info
DEBUG:SCRIPT: 
{
  normal = vmath.vector3(0, -1, 0),
  position = vmath.vector3(220.70994567871, 70.166679382324, 0),
  other_position = vmath.vector3(237.7099609375, 120.5647354126, 0.30000001192093),
  relative_velocity = vmath.vector3(0, 0, 0),
  other_id = hash: [/hero],
  other_mass = 0,
  group = hash: [hero],
  applied_impulse = 0,
  distance = -0.66667795181274,
  life_time = 0,
  mass = 0,
}

DEBUG:SCRIPT: === end message info
DEBUG:SCRIPT: +++++++ end test

```

my hero GO

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/d/db2b8176e587a4ac0c9dc173d43a628b173d7613.png)

my dino go

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/3/3f7a92dd23e768136dab8033bb89fe7bb02d2c77.png)

any ideas?

---

<div class="post-metadata">

**Author:** ![matheusvieiradepaula](https://forum-defold.b-cdn.net/letter_avatar_proxy/v4/letter/m/f04885/32.png) [@matheusvieiradepaula](https://forum.defold.com/u/matheusvieiradepaula)\
**Post date:** [January 14, 2017, 3:43pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/12 "2017-01-14T15:43:32Z")

</div>

Hello my friend! I don’t know if I really understand what do you want to do, but I have this piece of code that helps me a lot…

I put this inside the script attached to the factory, in your case, I think it’s the dino script:

```lua
this_id = tostring(go.get_id())
this_id = this_id:sub(8, -2)--hash: [/]

```

Sorry if isn’t what you are looking for…

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [January 14, 2017, 5:32pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/13 "2017-01-14T17:32:01Z")

</div>

I wouldn’t rely on string operations, since the strings won’t be available in release builds.

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [January 14, 2017, 5:39pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/14 "2017-01-14T17:39:16Z")

</div>

Hi @jhonatanvinicius!

A few things:

1. I think you have a typo: In your screenshot, the collision object is called “foot\_girl”, but in your code, you have written “footgirl”
2. I would enable the debug physics rendering to see that the feet actually are where you think they are.

---

<div class="post-metadata">

**Author:** ![Davej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/davej/32/3451_2.png) [@Davej](https://forum.defold.com/u/Davej)\
**Post date:** [January 14, 2017, 5:43pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/15 "2017-01-14T17:43:01Z")

</div>

You need to change the group of the hero collision object foot\_girl to foot\_girl, if you want to check different collisions objects on the same game object, they must belong to different groups, else all collisions will be checked under the same group

---

<div class="post-metadata">

**Author:** ![Davej](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/davej/32/3451_2.png) [@Davej](https://forum.defold.com/u/Davej)\
**Post date:** [January 14, 2017, 5:44pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/16 "2017-01-14T17:44:50Z")

</div>

Yes @Edgaronfo, thats right, but at least then you can check for a specific collision, if he wants to still use that area under hero, he can always place another collision object int the same area and call it hero still.

---

<div class="post-metadata">

**Author:** ![Edgaronfo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/edgaronfo/32/18438_2.png) [@Edgaronfo](https://forum.defold.com/u/Edgaronfo)\
**Post date:** [January 14, 2017, 5:55pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/17 "2017-01-14T17:55:29Z")

</div>

Ok,

In this specific case, your dino is checking for the hero, and NOT the hero for the dino, so the collisions that will be sent as `sender` will be you dino’s, that is why you receive _“collisionobject”_ as your `sender`.

> [@jhonatanvinicius](#):
>
> DEBUG:SCRIPT: message sender: [main:/instance1#collisionobject]

So if you want to know if you hero’s feet got bitten, you have to put code in your hero’s script, then you will be able to receive the hero’s collisions as senders.

Try this in your **hero.script** :

```lua
if message_id == hash("contact_point_response") then
       if message.group == hash("dino") then
	 		print("message sender: " .. sender)

```

and your result will be something like:  
`DEBUG:SCRIPT: message sender: [main:/hero#foot_girl]`

---

<div class="post-metadata">

**Author:** ![jhonatanvinicius](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonatanvinicius/32/2788_2.png) [@jhonatanvinicius](https://forum.defold.com/u/jhonatanvinicius)\
**Post date:** [January 14, 2017, 8:26pm UTC](https://forum.defold.com/t/how-to-check-the-objectcollision-that-send-message-solved/3975/18 "2017-01-14T20:26:47Z")

</div>

yeah it is working now!!!

you are right! @Edgaronfo.

I have learned a important thing about collisionObject today. here is may error:

 ![](https://forum-defold.b-cdn.net/uploads/default/original/2X/7/77c929de851e80a76034bb3e44d2dd1af19e1e9d.png)

I was trying “teach” to dino when he should die… but defolt dont tell to receiver the id of other collision object. basically a GO/script has access only to own object collisions.

Now this is my information path:  
1 - in girl i check if sensor foot make contact with dino…  
2 - so i send a message to dino with command “die”  
3 - the dino receive the command and send a return message to girl telling his coordinates Y and starts his die animation  
4 - the girl receives the message with coordinate and start to jump from dino’s head.

Really thanks for all help, guys.
