The Dollar Sign
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 19 of 28.
To change one of the robot's children, the script first has to find it. Write $ and the child's name, as it is shown in the Scene tab:
$Bulb.position.y -= 6That lifts the bulb on the antenna and leaves the rest of the robot in place. $Bulb is the node, so you can read and change anything on it.
A child's position is measured from its parent. The left eye is at x = -13, 13 pixels left of the robot's middle.
Names must match exactly, capitals included. $lefteye finds nothing.
Challenge
EasyMake the robot look to the right.
- In
_ready(), move$LeftEye4pixels right. - Move
$RightEye4pixels right too.
Press Play: both eyes look right, and the robot stays put. Then Check.
Try it yourself
extends Node2D
func _ready():
pass
All lessons in Nodes and Scenes
Practice on your own: Godot playground