Set a Position
Part of the Nodes and Scenes section of Coddy's Godot journey. Lesson 5 of 28.
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
EasyMove the robot to a new starting place.
- In
_ready(), replacepasswith a line that setspositiontoVector2(100, 250). - Keep
xfirst, theny.
Press Play: the robot stands on the left, just above the floor. 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