# Collision responses for specific collision objects

**URL:** <https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496>\
**Category:** Questions\
**Created:** [January 18, 2025, 1:53am UTC](https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496 "2025-01-18T01:53:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henry\_lindfield](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/henry_lindfield/32/38326_2.png) [@Henry\_lindfield](https://forum.defold.com/u/Henry_lindfield)\
**Post date:** [January 18, 2025, 1:53am UTC](https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496/1 "2025-01-18T01:53:13Z")

</div>

Im trying to stop my sheep from moving through my fence using collision objects - however I don’t want my sheep to be affected by their own collision objects so I use this code:

 ![image](https://forum-defold-uploads.b-cdn.net/original/3X/5/c/5cc2720ab109df510592af208a3a7f4efb29231b.png)

Is this right? My fence’s collision object has the group “fence” but when i run my program they just move right through it. What am i getting wrong?

Any help much appreciated : )

---

<div class="post-metadata">

**Author:** ![Henry\_lindfield](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/henry_lindfield/32/38326_2.png) [@Henry\_lindfield](https://forum.defold.com/u/Henry_lindfield)\
**Post date:** [January 18, 2025, 2:11am UTC](https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496/2 "2025-01-18T02:11:08Z")

</div>

Furthermore, Is there a better more robust way of stopping a game object passing through a wall. This only seems to work up to a point until they start to phase through the fence.

---

<div class="post-metadata">

**Author:** ![SuperEly](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/superely/32/36691_2.png) [@SuperEly](https://forum.defold.com/u/SuperEly)\
**Post date:** [January 18, 2025, 12:04pm UTC](https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496/3 "2025-01-18T12:04:55Z")

</div>

I have tried many methods to prevent one object from entering another, or passing through another. But in the end I was only able to do this with dynamic objects.

---

<div class="post-metadata">

**Author:** ![Potota](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/potota/32/33404_2.png) [@Potota](https://forum.defold.com/u/Potota)\
**Post date:** [January 20, 2025, 3:32am UTC](https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496/4 "2025-01-20T03:32:20Z")

</div>

> [@Henry\_lindfield](#):
>
> however I don’t want my sheep to be affected by their own collision objects

That’s what the group and mask options on collision objects are for. Set the sheep collision objects to have group `sheep` and mask `fence`, then set the fence objects to have group `fence` and mask `sheep`.

---

<div class="post-metadata">

**Author:** ![Pawel](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/pawel/32/24623_2.png) [@Pawel](https://forum.defold.com/u/Pawel)\
**Post date:** [January 20, 2025, 5:35am UTC](https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496/5 "2025-01-20T05:35:48Z")

</div>

Do you have collision objects set correctly? E.g. does `Mask` property of fence matches `Group` of sheep and vice versa? Put a simple print inside your code and check if collision happens 😉

> **[Collision objects in Defold](https://defold.com/manuals/physics-objects/)**
>
> A collision object is a component you use to give a game object physical behaviour. A collision object has physical properties and a spatial shape.

Ahh, yes, I see you also made another post with a video, the approach is problematic:

> [@Lots of game objects interacting with one wall](https://forum.defold.com/t/lots-of-game-objects-interacting-with-one-wall/79501/8):
>
> How are you moving those sheep? Are you using go.set\_position? If so it is the cause.

Print out the values you are setting (or use debugging to investigate them)

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [January 20, 2025, 6:14am UTC](https://forum.defold.com/t/collision-responses-for-specific-collision-objects/79496/6 "2025-01-20T06:14:12Z")

</div>

> [@Henry\_lindfield](#):
>
> Furthermore, Is there a better more robust way of stopping a game object passing through a wall.

I would recommend that you use a slightly more advanced collision resolver as described here: [Resolving kinematic collisions in Defold](https://defold.com/manuals/physics-resolving-collisions/)
