Thanks very much, Marc.
Apologies the block code hasn’t worked properly, maybe because of the @?
I have 2 players. They each have an Area2d on them.
When one player walks into the other, the below code is run.
What I can see happening is that only the host is running the code that prints “My ID with rpc” Because it’s printing 1 instead of 1006263358. I can see what the code is doing, printing the Host’s Id out in both instances of the game. I just don’t know enough to get it to run code only for the peer who is being grappled.
What I’d like to be able to do is get the second player to print their id, which is 1006263358.
If I can do that I should be able to call the grapple code on the second player (because I need them to play an animation when they are being grappled)
For grappling
func _on_body_area_2d_area_entered(area):
# Players should only run their own grapple code
if owner_id != multiplayer.get_unique_id():
return
var me = global_position.y
var target = area.global_position.y
var result = abs(me-target)
if area.name == "PlayerBodyArea2D" && result <= reachDistance:
if velocity.x != 0:
enemy_being_grappled = area.get_parent().get_parent()
#
isGrappling = true
velocity = Vector2(0,0)
print("My ID " + str(owner_id) + " is grappling player " + str(enemy_being_grappled.owner_id))
print_id.rpc()
@rpc(“call_local”, “authority”, “reliable”)
func print_id():
print("My ID with rpc " + str(owner_id))
And the output is