0 votes

im trying to make my player's arm rotate towards my cursor but it rotates very slightly and in the wrong direction here's my code:

func arm_follow():
var mouse_player_dif = get_global_mouse_position() - $"detective spritesheet/arm_joint".position  
$player_arm.rotation_degrees = rad2deg(atan2(mouse_player_dif.y,mouse_player_dif.x))
in Engine by (120 points)

1 Answer

0 votes

in the atan2() function, the first input shoud be the x value, and the second one the y value. in your code, you put y first then x.

also, you shouldnt have to use the rad2deg() func because you can just set the rotation in radians to the rotation property of the arm (since it reads rotation in radians already)

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