Move a Node Once
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 6 of 28.
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
EasyMove the robot from where it stands when the game starts.
- In
_ready(), move it150pixels left with-=onposition.x. - Then move it
40pixels up, onposition.y.
Press Play: the robot starts up and to the left of the middle. Then Check.
Try it yourself
extends Node2D
func _ready():
pass
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