0 votes

func physicsprocess(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?

Godot version 3.3.2 Stable windows 64bit
in Engine by (15 points)

1 Answer

+1 vote
Best answer

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

by (60 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.