Menu
CoddyTech

A Camera That Follows

Part of the Game Feel section of Coddy's Godot journey. Lesson 8 of 23.

This level is 1600 pixels wide, but the window shows only 640. When the robot walks right, it leaves the screen. A Camera2D node decides which part of the level is on screen.

The view is centered on the camera. Make the camera a child of the player, and it moves with the player. The player then stays in the middle of the screen.

var camera = Camera2D.new()
$Player.add_child(camera)

Camera2D.new() makes a camera node, and add_child puts it under the player. The first camera added to the game becomes the one the screen uses.

challenge icon

Challenge

Easy

In level.gd, make a Camera2D and add it as a child of $Player. Walk right with the arrows or D. The robot should stay in the middle of the screen.

Try it yourself

extends Node2D

func _ready():
	pass
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Game Feel

Practice on your own: Godot playground