This lesson focuses on covering the basics of how object hierarchies work in Zilch Engine.
Learning Objectives
- Object hierarchy creation
- Transforming hierarchies
- World-space values and local-space values
- Recognizing non-uniform scale problems
Level Setup
- Command : New Project
- Create a new project using the {nav icon=clone, name=Empty 2D Project} template
- Command : CreateSprite
- In the
Properties Window
- Rename Sprite object to
ParentSquare
- Under Sprite
- Set VertexColor to
[R:255, G:0, B:0, A:1.00]
- Command : CreateSprite
- In the
Properties Window
- Rename Sprite object to
ChildSquare
- Under Transform
- Set Translation to
[1, -1, 0]
- Under Sprite
- Set VertexColor to
[R:0, G:0, B:255, A:1.00]
- In the
Objects Window
Drag and drop
ChildSquare object on top of ParentSquare object
Parenting
As you have probably noticed, by dragging and dropping an object onto another, we've attached the former to the latter in a process called parenting. We then refer to this group of objects as a hierarchy, and it adopts new behaviors, most notably with respect to transformations. Let's take a look:
- Select : ParentSquare object
- Experiment with Translation , Rotation and Scale
Transforming the ParentSquare object
Notice that, when we apply a transformation to the parent object, it is propagated to the child object. However, if we apply transformations to the child, it won't affect the parent.
Transforming the ChildSquare object
If we look at the Transform component (in the Properties Window
) of both objects while applying transformations to the ParentSquare object, we notice that while its transform values are modified, the ChildSquare object's values remain the same. In Zilch Engine, the Transform values displayed on a root object (top parent of a hierarchy) correspond to their world values; that is, the transform values relative to the space's origin at [0, 0, 0]
. Meanwhile, transform values for child objects are displayed as local values; that is, the offset modifications relative to the parent object's values.
The Properties Window
showing the ParentSquare object and ChildSquare object objects, respectively
Notice the parent's world value is being modified, while the child's local value remains the same.
Non-Uniform Scale
When dealing with object Hierarchies, one can accidentally stumble on the problem of non-uniform scale. This can be seen when, for example, a parent object is scaled non-uniformly (that is, its X, Y, and Z scale values aren't all the same) and its child object of it is rotated.
This produces an often undesired shear effect, and is usually best avoided by making sure the parent object is always uniformly scaled. It should be noted that shearing does not affect the shape of colliders.