Created
January 13, 2024 06:52
-
-
Save lubien/46e5d1e43d055da13e2b3ca158839f25 to your computer and use it in GitHub Desktop.
godot 4.2 smooth switch between cameras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
var camera2D: Camera2D | |
var tween: Tween | |
func _ready(): | |
camera2D = $Camera2D | |
func transition_camera2D(from: Camera2D, to: Camera2D, duration: float = 1.0) -> void: | |
if transitioning: return | |
# Copy the parameters of the first camera | |
camera2D.zoom = from.zoom | |
camera2D.offset = from.offset | |
camera2D.light_mask = from.light_mask | |
# Move our transition camera to the first camera position | |
camera2D.global_transform = from.global_transform | |
# Make our transition camera current | |
camera2D.make_current() | |
tween = create_tween() | |
tween.set_parallel(true) | |
tween.set_ease(Tween.EASE_IN_OUT) | |
tween.set_trans(Tween.TRANS_CUBIC) | |
tween.tween_property(camera2D, "global_transform", to.global_transform, duration).from(camera2D.global_transform) | |
tween.tween_property(camera2D, "offset", to.offset, duration).from(camera2D.offset) | |
tween.play() | |
await tween.finished | |
to.make_current() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment