I get a warning saying that InterpolatedCamera has been deprecated. Is there a replacement or do we just use the Camera node instead?
You will need to use the Camera node. You can recreate InterpolatedCamera's functionality with a custom script and Transform's interpolate_with function inside of _process.
Looking at the C++ code, it would translate to:
extends Camera3D
@export
var target: NodePath
@export
var enabled := true
@export_range(0, 1, 0.01)
var speed := 1.0
func _process(delta):
var target_node = get_node(target)
if not enabled or not target_node:
return
var move_delta = speed * delta
var target_transform = target_node.global_transform
global_transform = global_transform.interpolate_with(target_transform, move_delta)
if target_node is Camera3D and target_node.projection == projection:
var new_near = lerp(near, target_node.near, move_delta)
var new_far = lerp(far, target_node.far, move_delta)
if target_node.projection == PROJECTION_ORTHOGONAL:
set_orthogonal(lerp(size, target_node.size, move_delta), new_near, new_far)
else:
set_perspective(lerp(fov, target_node.fov, move_delta), new_near, new_far)
Or something close to it. Didn't actually test it!
For anyone getting here, I also found a simpler Hierarchy and a normal Camera works really well! Like this:
The normal Camera being a direct child of the SpringArm, and you don't need to make it toplevel, as the SpringArm will take care of smoothly moving it forwards and backwards. Then you can use either the tween or the AnimationPlayer to animate the SpringArm's position and/or length to get the camera in the Shoulder position later on in the course.
The question was about Godot 4. The syntax Razoric used is Godot 4 syntax at the time of posting, in 2020. Those are export annotations, which were introduced in the new version of GDScript. I think that now you may need to write them on a single line, like so:
@export var target: NodePath
@export var tagert: NodePath
Did not work, but it led me looking into GDScript exports. Thanks Nathan!
I just did something like this
export(float, 0, 100, 0.01) var speed := 1.0
based on the docs: Introduction to exports
EDIT: I think we all misunderstood that you were asking how to code your own InterpolatedCamera node in Godot 4.
This @export var notation is Godot 4 syntax. If you use Godot 3, it won't work.
But in Godot 3, the InterpolatedCamera is still present so you don't need to code your own node. Being deprecated in Godot 4 isn't an issue if you're making your game in Godot 3.
That aside, yes, in Godot 3, the syntax is like this:
export var speed := 1.0
Without the @ sign.