PARENTING
PARENTING
Parenting is an important concept to understand when working with the Godot Engine.
Parenting is an important concept to understand when working with the Godot Engine.
It is used to create relationships between nodes, allowing them to inherit properties such as position, rotation and scale.
It is used to create relationships between nodes, allowing them to inherit properties such as position, rotation and scale.
Any node that isn’t the root node will be a child of at least one parent.
Any node that isn’t the root node will be a child of at least one parent.
Player Scene
Player Scene
In our Player Scene, Coin is already a child of the Player.
In our Player Scene, Coin is already a child of the Player.
Let's add another child node.
Let's add another child node.
Right-Click the Player and select Add Child Node.
Right-Click the Player and select Add Child Node.
This time add a CollisionShape2D
This time add a CollisionShape2D
We can add a Shape property
We can add a Shape property
to the CollisionShape2D node,
to the CollisionShape2D node,
we will be using the RectangleShape2D.
we will be using the RectangleShape2D.
This can then be scaled to the size of the player sprite
This can then be scaled to the size of the player sprite
using the orange circles on the edge of the rectangle
using the orange circles on the edge of the rectangle
Anything done to the Parent will be done to the Child
Anything done to the Parent will be done to the Child
If we Scale, Move or Rotate the Player
If we Scale, Move or Rotate the Player
the Collision box we added will do the same.
the Collision box we added will do the same.