Melee hitboxes rotating incorrectly

Godot Version

4.6.2

Question

I am working on making a melee attack for my game, but the hitboxes are oriented wrong. here is my code, let me know if there is other code needed. Sorry if this is an obvious fix, I am new to godot

extends Area2D
class_name Melee

@onready var collision := $CollisionShape2D
@onready var animation_player = $"melee animations/AnimationPlayer"
@onready var sprite = $"melee animations/Sprite2D"



var facing
var direction: Vector2


func _ready():
	match facing:
		0: # UP
			rotation = deg_to_rad(0)
			animation_player.play("up_slash")
			print(animation_player.current_animation)
		1: # DOWN
			rotation = deg_to_rad(180)
			animation_player.play("up_slash")
			print(animation_player.current_animation)
		2: # LEFT
			rotation = deg_to_rad(180)
			animation_player.play("right_slash")
			print(animation_player.current_animation)
		3: # RIGHT
			rotation = 0
			animation_player.play("right_slash")
			print(animation_player.current_animation)
	$melee_timer.start(0.75)
	
	

func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
	pass # Replace with function body.


func _on_body_entered(body):
	if body.is_in_group("enemy"):
		body.disable_target()   
		#queue_free()


func _on_melee_timer_timeout() -> void:
	queue_free()

The problem is that you can’t just rotate it, you need to move it. The easiest thing to do at this point for you, is just to move it in the editor until it is in the right place, and copy the position coordinates for each place. Then apply those in your code. You may not even need rotation.

I just thoguht of doing that and am working on doing it right now. Thank you for confirming my thoughts!

Hi, you have a couple of logic errors in the angles and structure. The main problem is that DOWN and LEFT share the same value of 180. In Godot 2D, 0 degrees is to the right (positive x-axis).