Collision responses for specific collision objects

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

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 : )

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.

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.

1 Like

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.

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 :wink:

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

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

I would recommend that you use a slightly more advanced collision resolver as described here: Resolving kinematic collisions in Defold