extends Area2D
# 弹开的力度(像素)
@export var push_dist: float = 5.0
func _physics_process(_delta):
var bodies = get_overlapping_bodies()
for body in bodies:
# 排除自身(父节点)
if body == get_parent():
continue
# 检查对方是否属于特定组
if body.is_in_group("Enemy"):
var parent = get_parent() as CharacterBody2D
if parent:
# 根据与对方的位置关系强制左右移动
var direction = 1 if parent.global_position.x > body.global_position.x else -1
# 通过直接重写坐标,忽略物理运算将其推开
parent.global_position.x += direction * push_dist