In Completing Animation Challenge where Rick is creating a parent object - e.g. Cactus and then makes a child object called Body, he moves the sprite renderer to it. However he doesn’t move the Rigid body to the Body - why is that? Doesn’t it make more sense for the Body, which has the sprite on in, to have the Rigid body attached to it?
Hi Jamie,
The Rigidbody2D and Collider2D remains on the game object we move via code: the parent.
But I don’t understand why? When I put mine on the child (Body) it works fine.
In my mind it makes more sense to put the Rigidibody and collider around the physical representation (which is the Sprite) which is under the Body.
A lot of things work in Unity.
We moved the visual things to the body to be able to animate the visual things without risking a conflict with our code which manipulated the same Transform object before we created the child object.
The Rigidbody2D is controlled by the physics simulation. If you animate something on the same game object which is also affected by the physics, you will very likely get a problem.
For this reason, we keep the visual stuff and the rest separated.
Nevertheless, please feel free to assign the Rigidbody2D component to the child. There is always a chance that it will work without any problems. If you want to be on the safe side, keep the Rigidbody2D component on the game object which you move.
Hi Nina
Thank you for the explanation.
I did some further research on what you said and did indeed find:
“ wrap animated objects inside an empty game object with a rigidbody and collider. this way you can handle smaller motions via animations while keeping the wrapper available to physics behaviours.”
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.