If statement not working

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lightfos

func _physics_process(delta):

var current = animationTree._whatisplaying()
print(current)
    #right
if current == Vector2(1, 0):
	ray.rotation_degrees = -90
#Left
elif current == Vector2(-1, 0):
	ray.rotation_degrees = 90
#Up
elif current == Vector2(0, -1):
	ray.rotation_degrees = 180
#Down
elif current == Vector2(0, 1):
	ray.rotation_degrees = 0
#TopRight
elif current == Vector2(0.707107, -0.707107):
	ray.rotation_degrees = -135

The current variable holds a returned value from another script which gives the blend position in my animationtree node. This if statement rotates the RayCast2D node based on the blend position. For example if I move to the right the animation “Walk Left” will be played and the blend position ( 1, 0) is given. I know this since ive done print(current) and it gives the proper cords. Now if i get (1,0 ) i want the raycast to rotate by
-90 degrees. This does work and it works for all 4 cardinal directions but it does not work for topright, topleft, bottomleft, bottomright. Like for TopRight I get the blend position cords as (0.707107, -0.707107) (print(current) gives this) but the raycast does not rotate. Neither does any other code executes under that elif statement. Why is this happening?

:bust_in_silhouette: Reply From: zub_zob

Don’t use == with Vector2s or floating point numbers in general.
You can convert the vector to degrees that way:

ray.rotation_degrees=rad2deg(current.angle()-PI/2.0)