How to make camera follow player in Godot

In this tutorial, we will see how to make a camera follow the player in Godot. I will be using Godot version 3.4.2 for this tutorial. If you use Unity, check out camera follow player Unity tutorial.

Camera follow player in Godot 2D.

  1. Right click on your scene and click add node. Seach for Camera2D and add it to the scene.
  2. Select the Camera2D node and go to the inspector window.
  3. Add a new script to camera and call it player_follow.
  4. Click the down arrow near the script and click edit.
  5. Copy and paste the code below in to the script.
  6. Save the script.

Camera follow script for 2D

extends Camera2D

var player

func _ready():
	player= get_node("/root/Scene/Icon")

func _process(delta):

Save and run the game. The camera will follow the player movement in x and y axis.

Camera follow player in Godot 3D

Camera follow player in Godot gif.
  1. Add Camera node in place of Camera2D
  2. Set your camera angle as required.
  3. In our case the player moves only in the x axis so let’s add the script for the camera to move only in the x axis.
  4. Add a script to the camera object.
  5. Copy and paste the code below.
  6. Save the code and run the project.

Camera follow script for 3D

extends Camera

# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var player

# Called when the node enters the scene tree for the first time.
func _ready():
	player= get_node("/root/Scene/glass cube")

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
#	pass

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.