0
\$\begingroup\$

Here's a declaration of Vector2 camera_input. And, it comes out to be invalid. I'm using Godot 4.0.1.

Code:

extends CanvasLayer

@onready var camguide_y = get_parent().get_node("character_1_controller/camguide_y")
@onready var camguide_x = get_parent().get_node("character_1_controller/camguide_y/camguide_x")

var joystick_index = -1
var attack_index = -1
var s1_index = -1
var s2_index = -1
var dodge_index = -1
var camera_index = -1
var camera_input = Vector2.ZERO
var rotation_velocity_x = 0
var rotation_velocity_y = 0

func _unhandled_input(event):
    if event is InputEventScreenTouch:
        if event.pressed:
            if Input.is_action_just_pressed("joystick_action"):
                joystick_index = event.index
            elif Input.is_action_just_pressed("attack_action"):
                attack_index = event.index
            elif Input.is_action_just_pressed("s1_action"):
                s1_index = event.index
            elif Input.is_action_just_pressed("s2_action"):
                s2_index = event.index
            elif Input.is_action_just_pressed("dodge_action"):
                dodge_index = event.index
            else:
                camera_index = event.index
        else:
            if Input.is_action_just_released("joystick_action"):
                joystick_index = -1
            elif Input.is_action_just_released("attack_action"):
                attack_index = -1
            elif Input.is_action_just_released("s1_action"):
                s1_index = -1
            elif Input.is_action_just_released("s2_action"):
                s2_index = -1
            elif Input.is_action_just_released("dodge_action"):
                dodge_index = -1
            else:
                camera_index = -1
    if event is InputEventScreenDrag:
        if event.index == joystick_index:
            pass
        if event.index == camera_index:
            camera_input = event.relative
        
        
        
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
    rotation_velocity_x = lerp(rotation_velocity_x, camera_input.x * 0.4, delta*10.0)
    rotation_velocity_y = lerp(rotation_velocity_y, camera_input.y * 0.15, delta*10.0)
    camguide_x.rotate_x(deg_to_rad(rotation_velocity_y))
    camguide_y.rotate_y(deg_to_rad(rotation_velocity_x))
    camguide_x.rotation.x = clamp(camguide_x.rotation.x, -0.5, 0.5)
    camera_input = Vector2.ZERO

Error message: Invalid type in utility function 'lerp'. Cannot convert argument 2 from float to Nil

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

As mentioned in the lerp documentation:

Variant lerp ( Variant from, Variant to, Variant weight )

...

Both from and to must be the same type.

camera_input.x is a float (because that's what Vector2.ZERO is made up of) whereas rotation_velocity_x is inferred as an int (because 0 is an integer).

Try changing the declaration to:

var rotation_velocity_x = 0.0

or better yet use static typing:

var rotation_velocity_x : float = 0.0
\$\endgroup\$
1
  • \$\begingroup\$ It. works, thank you so much, I have tried to focus on camera_input and ignored the rotation velocity. \$\endgroup\$
    – Tyler Chen
    Commented Apr 12, 2023 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .