How to Design Wall Blocking for My Attack

Godot Version



I’m currently using Area2D as a hitbox and toggling it as the player’s attack. Since the attack range can exceed two tile grids, it can hit enemies on the other side of the wall. How can I design it to detect the wall and prevent the attack from passing through?

Currently, I use two CollisionShape2D of different sizes and use RayCast2D to check if there is a wall in front to control whether the larger CollisionShape2D is enabled. However, this has increased complexity when I expand the attack methods (e.g., attacking upward, backward, and other attack actions). I am looking for an elegant solution to this problem.

Using a raycast is the correct way. You could use raycast before you cast the spell to check how far it reaches and then set the area2d size according to the range the raycast allows

1 Like