0 votes

Hello I'm having trouble on using my [var isfacing], in an [if] statement. The [func facing] works but for some reason when I use it as a check for my [func dash], the [if] statement doesn't go through. And yes [func dash], and [func facing], is in [func _physicsprocess].

My apologies if my english/terminology is off.

 var is_facing = Vector2.ZERO

   func facing():
        if Input.is_action_pressed("Left"):
            var is_facing = Vector2.LEFT
    #       print(is_facing)

        elif Input.is_action_pressed("Right"):
            var is_facing = Vector2.RIGHT
    #       print(is_facing)

    func dash():
        if Input.is_action_just_pressed("Dash") and is_facing == Vector2.LEFT:
            velocity.x = velocity.x - dash_lenth
            print("dash left")

        elif Input.is_action_just_pressed("Dash") and is_facing == Vector2.RIGHT:
            velocity.x = velocity.x + dash_lenth
            print("dash right")
in Projects by (12 points)

1 Answer

0 votes

Assuming that code you haven't shown is working as you describe, my first guess is that you're getting bit by a floating point error that's causing your vector equality checks to fail (== Vector2.LEFTfor example).

If that is indeed the problem changing that to something like this might fix the issue...

if Input.is_action_just_pressed("Dash") and is_facing.is_equal_approx(Vector2.LEFT)

That'll return true if the compared vectors are very close to being equal, with requiring them to be exactly equal...

by (10,756 points)
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.