I am trying set sprite based on direction of node facing an enemy.
#face nearest marble
# >>>>> self.look_at(nearest_marble.position)- I changed to rotate for smoothness of movement
var velocity = global_position.direction_to(nearest_marble.global_position)
rotation = velocity.angle()
print (rotation_degrees)
if rotation_degrees <= 22.5 and rotation_degrees >= -22.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(right)
if rotation_degrees <= 67.5 and rotation_degrees >= 22.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(bott_right)
if rotation_degrees <= 112.5 and rotation_degrees >= 67.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(bott)
if rotation_degrees <= 157.5 and rotation_degrees >= 112.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(bott_left)
if rotation_degrees <= -22.5 and rotation_degrees >= -67.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(top_right)
if rotation_degrees <= -67.5 and rotation_degrees >= -112.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(top)
if rotation_degrees <= -112.5 and rotation_degrees >= -157.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(top_left)
if rotation_degrees <= -157.5 and rotation_degrees >= 157.5:
$body/CollisionShape2D/shooter_sprite_button.set_normal_texture(left)
The only one that works right is for right. Maybe its my dyslexia but I cant see my mistake.
Or if there is a better way to do this?