InterpolatedCamera will be deprecated in Godot 4.0. What would be a replacement?

Kevin Do(TITLEplayer)

I get a warning saying that InterpolatedCamera has been deprecated. Is there a replacement or do we just use the Camera node instead?

  • Razoric replied

    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
    var target: NodePath
    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:
    	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)
    			set_perspective(lerp(fov, target_node.fov, move_delta), new_near, new_far)

    Or something close to it. Didn't actually test it!

    2 loves
  • T
    Kevin Do(TITLEplayer) replied

    Sorry for the very late reply, could you link me where that C++ code is?

  • Nathan Lovato replied

    There you go: https://github.com/godotengine/godot/blob/3.2/scene/3d/interpolated_camera.cpp

  • Daniel Queiroz Porto(daniel-queiroz-porto) replied

    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.

    1 love
  • Nathan Lovato replied

    Thanks for sharing!

  • T
    Kevin Do(TITLEplayer) replied

    Thanks guys, Razoric's answer is working for me. I just had to tweak the Offset Camera in Aim state.

    What is  @export and  @export_range ? Godot 3.5.0 is giving me errors and saying it's not valid.

  • Nathan Lovato replied

    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
  • T
    Kevin Do(TITLEplayer) replied
    @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

  • Nathan Lovato replied

    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.

    1 love