SpiralCircus

We have rigged a character with several bounding boxes to provide an approximate collision shape. In unity I can use the BoundingBoxFollower script to create colliders that correctly follow the animations and report collision events etc, but these colliders do not actually respect collision constraints with other colliders in the scene, e.g. terrain. Is it possible to use BB followers to act as real rigid colliders that can't go through other colliders or is this a non-starter given how the bounding box follower is implemented in unity?
SpiralCircus
Posts: 9

Harald

If you really mean 3D terrain, then the problem I see is the general limitation in Unity that 2D Colliders, such as the PolygonCollider2D at your character, don't interact with 3D Colliders (where terrain counts as a 3D Collider). You could add 3D colliders such as a 3D BoxCollider to your character, however this will not match your polygon shape too well.

If by 'terrain' you mean it does not collide with other 2D Colliders attached to a Sprite that visualises terrain:
  1. Did you add a Rigidbody2D Component to the character's root GameObject?
  2. If you already added a Rigidbody2D, does it collide with a GameObject with static enabled and a BoxCollider2D added as a ground collider?
User avatar
Harald

Harri
Posts: 147

SpiralCircus

Sorry, I should be more clear:

Terrain is a 2D poly collider. Everything that collides in our game is in 2D.

1. Yes there is a dynamic rigidbody2D attached to the character and it's movement is physics-based (adding force to the RB).
2. Yes the collision matrix is properly set up and configured to collide with the relevant layers, both static and not static

If i add a standard unity collider, e.g. box2D or poly2D, to either the root gameobject with the SkeletonAnimation on it or to a child object, the collision works as intended, but if i add the bounding box follower and the bone follower it allows the player to pass through any other 2d collider. Collision events are still reported (OnCollisionEnter2D etc.) but it can pass through everything, both static and non-static.

I have tried adding RBs to the individual collider parts, tried both kinematic and dynamic, tried without RBs on the collider parts, having only one RB on the root object. In every combination the BBFollower colliders can pass through every other collider.

SpiralCircus
Posts: 9

Harald

Was your character-root Rigidbody set to Kinematic as well, or did you try changing all GameObjects to Dynamic? In general, on a Kinematic Rigidbody, OnCollisionEnter2D would then be called but no collision response would happen.

Unfortunately I don't understand why it does work when you add a child GameObject with a BoxCollider2D.

Could you maybe create a minimal Unity project that still shows the problem and send us a zipped package to contact@esotericsoftware.com?
User avatar
Harald

Harri
Posts: 147

SpiralCircus

Hi Harald,

Thanks for your response, I'll get back to you with an MWE asap, I'm not sure if I'll have time to get to it today, but i appreciate the help.
SpiralCircus
Posts: 9

Harald

Great, thanks!
User avatar
Harald

Harri
Posts: 147

SpiralCircus

Ok, i think i may have found the culprit.

I was making the MWE in a new project and I had my character in the scene when I played it. The no-collision problem did not occur, so i went back to our game and tried to figure out what was different. In our case it seems that the relevant difference is that we instatiate the character at runtime from a prefab.

What I hadn't noticed was that, even though I had deleted the auto-generated rigidbody from the child gameobject it was being added again on instantiate via BoundingBoxFollower.cs (line 147) calling SkeletonUtility.AddBoundingBoxAsComponent(...) which adds an rb if one is not present.

Having the rb on the child gameobject seems to prevent the overlap constraints from applying.
SpiralCircus
Posts: 9

Harald

Hm, that seems undesirable - I will have a look at it.

---

I just tested it both with and without prefab instantiation - it works in both cases and does not automatically add any Rigidbody2D at the child object.

What seems strange is that you mentioned
BoundingBoxFollower.cs (line 147)
whereas the call to SkeletonUtility.AddBoundingBoxAsComponent actually is in line 154 - have you maybe modified the file or are you using an old version?
User avatar
Harald

Harri
Posts: 147


Return to Unity