Set a Position
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 5 of 27.
A node's position is a Vector2: two numbers, x and y. x counts pixels to the right. y counts pixels down. The top left corner of the game is (0, 0), and this game is 640 pixels wide and 360 tall.
Set a position in _ready() to choose where a node starts:
func _ready():
position = Vector2(500, 100)That puts the robot near the top right. A bigger y means lower on the screen.
Challenge
EasyMake the robot start at x = 100, y = 250, on the left just above the floor.
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