So I am trying to create a slash & hit effect for my game, whenever that the player tries to hit an enemy, the player would cast a ray, the effect would appear at the collision position. how ever, the player's attack would hit multiple enemies. this is where the problem comes in, they ray would only hit and be blocked by the first enemy or worse, something else.
here is my code:
func _on_Attack_coli_body_entered(body: Node) -> void:
var slash_effect = preload("res://crs/effects/attackanim/swordslide.tscn").instance()
var spacestate = get_world_2d().direct_space_state
var result = spacestate.intersect_ray(global_position,body.global_position,["exclude every one but 'body'"])
slash_effect.position = result.position
slash_effect.rotation = (position - body.position).angle()+1.5
how can I make the raycast only cast on a particular body?