Topic was automatically imported from the old Question2Answer platform.
Asked By
MANdR_05
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.
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
func _ready():
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
var radian_angle_to_mouse=get_node("Sprite").global_position.angle_to_point(get_global_mouse_position())
var degree_angle_to_mouse=rad2deg(radian_angle_to_mouse)
#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