All Questions

Community

D
Kevin Do

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

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
    
    @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!