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
        $AnimatedSprite.play("Right")
    elif Input.is_action_pressed("ui_left"):
        input.x = -1
        $AnimatedSprite.play("Left")
    if Input.is_action_pressed("ui_up"):
        input.y = 1
        $AnimatedSprite.play("Up")
    elif Input.is_action_pressed("ui_down"):
        input.y = -1
        $AnimatedSprite.play("Down")
    else:
        input = 0
        $AnimatedSprite.stop()

    if input != Vector2.ZERO:
        velocity = input
    else:
        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 (96 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 (20,677 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 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 webmaster@godotengine.org with your username.