0 votes

hi, i use RPC method to send animation to other player screen, the problem is that when i press a key in player1 screen which belongs to player1, it works properly. but when i press the same key in player2 screen, it works again. what should i do to fix this problem?

func _input(event):
     if event.is_action_pressed("shoot"):
        right_shoot()
        rpc("right_shoot")

slave func right_shoot():
    do_something

and this is the codes belong to stage (player 1 and 2 instance to stage node)

func _ready():
    if (get_tree().is_network_server()):
        player2.set_network_master(get_tree().get_network_connected_peers()[0])
    else:
        player2.set_network_master(get_tree().get_network_unique_id())

(it is one on one game)

in Engine by (76 points)
edited by

1 Answer

0 votes

ok i created a boolean variable in singleton and added it to host and join function.
its true, when player is client and its false, when player is server and then used this variable in the above condition, it fixed my problem:

if global.client == true && event.isactionpressed("shoot"):
((for client))
if global.client ==false && event.isactionpressed("shoot"):
((for server))

:)

by (76 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.