Move a Node Once
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 6 of 27.
Setting position puts a node in an exact place. To move it by an amount from where it is, change position.x or position.y. += adds to a number:
position.x += 100That moves the node 100 pixels right. -= subtracts, so position.y -= 50 moves it 50 pixels up. Remember that y grows downward.
A move by an amount works wherever the node starts.
Challenge
EasyWhen the game starts, move the robot 150 pixels left and 40 pixels up from where it stands. Move it by amounts with += or -=.
Try it yourself
extends Node2D
func _ready():
pass
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Nodes and Scenes
1Your First Godot Game
What Is Godot?Ready Runs OncePrint in GodotThe Scene TreeSet a PositionMove a Node OncePractice on your own: Godot playground