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()
if current == Vector2(1, 0):
	ray.rotation_degrees = -90
elif current == Vector2(-1, 0):
	ray.rotation_degrees = 90
elif current == Vector2(0, -1):
	ray.rotation_degrees = 180
elif current == Vector2(0, 1):
	ray.rotation_degrees = 0
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: