Rigidbody2D and non-trigger child colliders!
Hello!
I have a simple question with colliders and rigidbodies just for 2D. I have a character gameobject with a Rigidbody2D attached to it with a circle collider, this also has a child gameobject with an extra collider in the child which is not a trigger. Now considering that the character is always going to be moving around, must I have a Rigidbody2D also attached to the child colliders?
The reason I'm asking is because I've read around on the interwebs that if a "solid" collider does not have a Rigidbody attached to it Unity assumes this collider is static and does not move and therefore saves on performance. So does the fact that the parent collider has a Rigidbody automatically let Unity know that these other solid child colliders will also be moving around?
Any help will be really appreciated :D.
Answer by Statement · Oct 31, 2015 at 12:16 PM
So does the fact that the parent collider has a Rigidbody automatically let Unity know that these other solid child colliders will also be moving around?
I don't know the internals of the 2D physics system, but the 3D physics system works (or at least worked like this some time ago when I was exploring it more in detail):
If you have a gameobject without a rigidbody, with any colliders, all non-rigidbody colliders will be rebaked if any of those object moves.
If you have a game object with a rigidbody, with any colliders, colliders will not be rebaked if you move the rigidbody.
If you have a game object with a rigidbody, with any colliders, colliders will be rebaked for that rigidbody if any of its colliders move relative to the rigidbody.
That is to say; given you have a rigidbody A and colliders B, C, and D
- A
B
C
D
Then moving B, C or D will rebake the collision data only for A, not the entire scene. If you want to move B, C and D without performance hits for rebaking (even if it's only limited to that particular rigidbody) then B, C and D should have kinematic rigidbodies.
Answer by hexagonius · Oct 31, 2015 at 11:30 AM
The root Rigidbody2D takes the children into account and forms a larger collider out of all of them. If you're past Unity 4.5. No performance impact here.
Your answer
Follow this Question
Related Questions
RigidBody becomes awake without a collision 1 Answer
Adding velocity to an object in a brick breaker game 0 Answers
Platforming character is jumping higher while walking 0 Answers
Is there an easy way to make a RigidBody2D collide with only one other RigidBody2D? 1 Answer
Why/How 2d tower of blocks collapse? 0 Answers