0 votes

For a mobile platformer project, I've been attempting to create a virtual joystick that registers multiple angles or degrees as either left or right movement only. I've been trying to use a range of degrees of the virtual joystick that are then sent to a kinematicbody2d, but haven't had any success so far. To illustrate further, if the joystick circle is comprised of 360 degrees with the right-most side being degree 0, traveling counter-clockwise around the circle, I'd like degrees 135 - 225 to register as LEFT and degrees 315 - 45 to register as RIGHT. I hope this makes sense. If anyone could point me in the right-most direction, it'd be truly valuable to me.

Godot version 3.2.3
in Engine by (20 points)

1 Answer

+1 vote

func direction(degree):
. if degree >= 135 and degree <= 255:
. . return Vector2.LEFT
. if degree >= 315 or degree <= 45:
. . return Vector2.RIGHT
. return Vector2.ZERO

by (2,688 points)
edited by

Thank you much. This seems very intuitive.

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.