Skip to content

A plugin for Godot 4 that adds a 2D cinematic camera that can be used to create smooth transitions between cameras

License

Notifications You must be signed in to change notification settings

HexagonNico/CinematicCamera2D

Repository files navigation

Cinematic Camera 2D plugin

A plugin that adds a VirtualCamera2D node and a CinematicCamera2D node that allow to create smooth transitions between cameras.

Installing the plugin in your project

The procedure is the same as other Godot plugins. See the Godot docs for a full explanation.

  1. Click the AssetLib tab at the top of the editor and look for Cinematic Camera 2D.

  2. Download the plugin and install the contents of the addons and the script_templates folders into your project's directory. You don't need the contents of the example folder.

  3. Go to Project -> Project Settings... -> Plugins and enable the plugin by checking "Enable".

It is also possible to install the plugin manually by downloading the zip archive from the Releases section.

Plugin contents

The plugin contains two script classes: VirtualCamera2D and CinematicCamera2D. Both can be added to your scenes as nodes through the "Create New Node" menu.

The VirtualCamera2D node contains the camera's data.

The CinematicCamera2D node is the actual camera and contains a reference to a virtual camera node.

Create node

Creating cinematic camera

Open the "Create New Node" menu and search for "VirtualCamera2D". Add this node in your level scene.

Virtual camera inspector

This node contains data about the camera's zoom level, offset, and limits.

Now add a "CinematicCamera2D" node and assign the virtual camera to the 'Virtual camera' property in the inspector. When you run the game, the cinematic camera will copy the properties of the virtual camera.

Cinematic camera inspector

Following the player

The cinematic camera also has a 'Follow node' property. Setting this property to your player's node will make the camera copy the player's global position, allowing you to create a camera that follows the player. Enable position smoothing in the camera's properties to create a smooth movement.

Create transitions between cameras

It is possible to create smooth transitions between cameras if there are more virtual cameras in the scene. If the camera's position smoothing is enabled and the virtual_camera property of the CinematicCamera2D is updated, the camera will move towards the new one.

Example:

@onready var cinematic_camera: CinematicCamera2D = $CinematicCamera

@onready var virtual_camera_1: Node2D = $VirtualCamera1
@onready var virtual_camera_2: Node2D = $VirtualCamera2

@onready var camera_trigger_shape: CollisionShape2D = $CameraTrigger/CollisionShape

func _on_camera_trigger_body_exited(body: Node2D) -> void:
	if body.position.y < camera_trigger_shape.position.y:
		cinematic_camera.virtual_camera = virtual_camera_2
	else:
		cinematic_camera.virtual_camera = virtual_camera_1

If the second camera has a different zoom, offset, or limits, the camera will slowly update its values towards the new ones.

About

A plugin for Godot 4 that adds a 2D cinematic camera that can be used to create smooth transitions between cameras

Topics

Resources

License

Stars

Watchers

Forks