It depends on how you want to go about it, but you could, in theory, do something like this (untested):
Player 1 code:
extends Node2D
# Other code here...
func _on_special_area_entered(area_node_entered):
print ("Player 1 entered Area2D node!")
# do whatever you need here...
Player 2 code:
extends Node2D
# Other code here...
func _on_special_area_entered(area_node_entered):
print ("Player 2 entered Area2D node!")
# do whatever you need here...
Area2D node code:
extends Area2D
# Other code here...
func _ready():
# If your players are using Area2D nodes for collision
# detection, then use the following:
connect("area_entered", self, "_on_area_entered_area2D")
# If your players are using RigidBody2D, KinematicBody2D, or StaticBody2D
# nodes for collision detection, then use the following instead:
# connect("body_entered", self, "_on_body_entered_area2D")
# For Area2D nodes:
func _on_area_entered_area2D(other_area_node):
print ("Area with name ", other_area_node.name, " entered!")
if (other_area_node.has_method("_on_special_area_entered") == true):
other_area_node._on_special_area_entered()
# For RigidBody2D, KinematicBody2D, and StaticBody2D nodes:
func _on_body_entered_area2D(other_body_node):
print ("Collision other node whose name is ", other_area_node.name)
if (other_area_node.has_method("_on_special_area_entered") == true):
other_area_node._on_special_area_entered()
There are other ways to do it, but that is one way you can work around the issue. Hopefully this helps!
(Side note: Welcome to the forums)