Child "Body" object

I’m still unclear about what purpose the “body” child object serves. What is gained by doing that and having the animator on the root and the sprite renderer on the child over having the sprite renderer and animator on the same root object?

Less work when creating new defenders, basically.

You just have to duplicate an existing defender, change only its name and Animator, and keep the transform and the collider. Then you can change the Body child object and its size without having to bother to rescale the collider component.

1 Like

In a lecture further on (“Collision Matrix in Script”), I think I got my answer.

Ben needed the grass-square collider for the tombstone defender to stay with the grass square the defender occupies, but it was moving when the tombstone moved because he had the animator animating the parent object, not the child “Body”. He also scaled and translated the sprites without affecting that grass-square area collider. So it’s looking like he structured it that way to decouple the square occupied from what’s going on inside that square. There’s actually two different concerns going on, so he needs two objects.

There are a couple of reasons to that:

*You can’t have a animator changing the transform of the object at the same time as the script, it is incompatible, that is why it is better to animate a child and change the transform of the parent;

*Sometimes you have more than one mesh or sprite being part of the same character, like a flying orb for example, or equipment, so it is better to move them as one using a parent gameobject, this makes easier to add different equipment and sprites to the character without compromising the animation;

It is harder to see in this lesson why it is better to make this way, but for more complex games it will be clearer


Great explanation, thank you.

1 Like

Privacy & Terms