D3/Level/Rope/Rope_Part.gd
2025-05-10 23:19:52 +08:00

36 lines
1.0 KiB
GDScript

extends RigidBody2D
signal player_entered(part: RigidBody2D)
signal player_exited(part: RigidBody2D)
func _ready() -> void:
# 设置碰撞检测
contact_monitor = true
max_contacts_reported = 4
# 连接信号
body_entered.connect(_on_body_entered)
body_exited.connect(_on_body_exited)
if get_parent().get_parent().debug_mode:
print("[RopePart] Name: ", name)
print("[RopePart] Collision layer: ", collision_layer)
print("[RopePart] Collision mask: ", collision_mask)
print("[RopePart] Contact monitor: ", contact_monitor)
print("[RopePart] Max contacts: ", max_contacts_reported)
func _on_body_entered(body: Node2D) -> void:
if get_parent().get_parent().debug_mode:
print("[RopePart] Body entered: ", body.name)
print("[RopePart] Body in player group: ", body.is_in_group("player"))
if body.is_in_group("player"):
player_entered.emit(self)
func _on_body_exited(body: Node2D) -> void:
if get_parent().get_parent().debug_mode:
print("[RopePart] Body exited: ", body.name)
if body.is_in_group("player"):
player_exited.emit(self)