0 votes

My code says the following:

    const maxval = 300
var velocity = Vector2.ZERO

func _physics_process(delta):
    var input = Vector2.ZERO
    if Input.is_action_pressed("ui_right"):
        input.x = 1
    elif Input.is_action_pressed("ui_left"):
        input.x = -1
    if Input.is_action_pressed("ui_up"):
        input.y = 1
    elif Input.is_action_pressed("ui_down"):
        input.y = -1
        input = 0

    if input != Vector2.ZERO:
        velocity = input
        velocity = Vector2.ZERO

# warning-ignore:return_value_discarded
    move_and_collide(velocity * delta * maxval)

But I'm getting this error:

  Invalid operands 'int' and 'Vector2' in operator '!='.

I have animations for movement but no Idle animations. And when I just use another code from another project, the animation either plays and doesn't stop or never plays.

in Engine by (101 points)

1 Answer

+1 vote
Best answer

You declared your input variable as a Vector2, and when there's input you change its x and y components. However, anytime you don't press "up" or "down" you set input = 0, which is an int. That is the source of your error: != can't compare an int to a vector.

by (21,979 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.