Menu
CoddyTech

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 icon

Challenge

Easy

Move the robot to a new starting place.

  1. In _ready(), replace pass with a line that sets position to Vector2(100, 250).
  2. Keep x first, then y.

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

Practice on your own: Godot playground