A plugin that adds a VirtualCamera2D node and a CinematicCamera2D node that allow to create smooth transitions between cameras.
The procedure is the same as other Godot plugins. See the Godot docs for a full explanation.
-
Click the AssetLib tab at the top of the editor and look for Cinematic Camera 2D.
-
Download the plugin and install the contents of the
addons
and thescript_templates
folders into your project's directory. You don't need the contents of theexample
folder. -
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.
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.
Open the "Create New Node" menu and search for "VirtualCamera2D". Add this node in your level scene.
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.
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.
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.