Camera Limits
Part of the Game Feel section of Coddy's Godot journey. Lesson 9 of 23.
The camera follows the robot past the edges of the level. At the start you can see the empty dark to the left and under the floor.
A Camera2D has four limits, in level pixels. The view never goes past them.
extends Camera2D
func _ready():
limit_left = 0
limit_right = 1600A limit is an edge of the view, not of the camera's center. With limit_right = 1600, the right edge of the screen stops at 1600. The camera's center stops 320 pixels earlier. limit_top and limit_bottom work the same way up and down.
Challenge
EasyKeep the view inside the level.
- This script is on the camera. In
_ready(), setlimit_leftandlimit_topto0. - Set
limit_rightto1600andlimit_bottomto360.
Press Play and walk to both ends: the view stops at the edges of the level. Then Check.
Try it yourself
extends Camera2D
func _ready():
pass
All lessons in Game Feel
Practice on your own: Godot playground