# How can i get and transform the mouse angle to a int number?

Attention Topic was automatically imported from the old Question2Answer platform.

I want to make a top down shooter with 360° aim animation like Metroid, but, how can transform the mouse angle position into 8 numbers? Like I want my character to be able to aim in 8 directions, in each direction he will change the sprite of aiming, like metroid, and I want a deadzone of 45° degress like, if he is aiming between 0 and 45 degrees, he will stay with the same sprite and keep rotating until he changes to the next zone. One more question, how can I stop the rotation to 0? When I try, It keeps rotating, I ended up making 2 sprites, one that always follows and is only visible when aiming and the sprite on top that is visible when stopped, but it’s too bad like that.

You can look at this: 8-Directional Movement/Animation :: Godot 3 Recipes

Enfyna | 2023-06-20 21:52

this is an example for 8 directions you can clean the code to be small
transform the mouse angle position into 8 numbers
godot 3.5.2 stable

``````    extends Node2D

pass

func _process(delta):
var hero=get_node("Sprite") # sprite node
var mouse_pos=get_global_mouse_position()
var sprite_pos=get_node("Sprite").global_position
#left
if(degree_angle_to_mouse>-22.5 and degree_angle_to_mouse<22.5):
hero.rotation_degrees=0
#left-up
if(degree_angle_to_mouse>22.5 and degree_angle_to_mouse<67.5):
hero.rotation_degrees=45
#up
if(degree_angle_to_mouse>67.5 and degree_angle_to_mouse<112.5):
hero.rotation_degrees=90
#up-right
if(degree_angle_to_mouse>112.5 and degree_angle_to_mouse<157.5):
hero.rotation_degrees=135
#right
if(degree_angle_to_mouse>157.5 and degree_angle_to_mouse<180 or degree_angle_to_mouse>-157.5 and degree_angle_to_mouse<-180):
hero.rotation_degrees=180
#right-down
if(degree_angle_to_mouse>-157.5 and degree_angle_to_mouse<-112.5):
hero.rotation_degrees=-135
#down
if(degree_angle_to_mouse>-112.5 and degree_angle_to_mouse<-67.5):
hero.rotation_degrees=-90
#down-left
if(degree_angle_to_mouse>-67.5 and degree_angle_to_mouse<-22.5):
hero.rotation_degrees=-45

pass
``````
``````hero.rotation_degrees = stepify(degree_angle_to_mouse,45)
``````

if I am not mistaken this line can replace all your if statements.

Enfyna | 2023-06-20 21:37