This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

When a player is in an area and then a certain key e.g. "E" presses something should happen to the player. But since I don't have the body in the input event, I don't know how to find out which player pressed the button and then modify the player body

in Engine by (107 points)

1 Answer

+2 votes
Best answer

You can do this

func get_input():
    if is_network_master():
        if Input.is_action_pressed("some_action_key"):
            #tell the server to do something to this player
            # id 1 is for server 

#function to do something (server)
remotesync func server_do_something_to_this_player():
    #your code to do something

    #then sync what server did to this player with everyone

remotesync func sync_what_server_did():
    #your code to sync changes
by (753 points)
selected by

Oke Thanks that works. Now another question when i spawn a new Objects then with physics and one player hit it the object is not moving at both screens to the same direction. So the Physics of the objects are not sync how do i change that?

? Can u help me with that

You need to use Authoritarian networking model (Server controls everything).
As the game is running on different devices , There will be no physics sync. To sync physics you need to consider only server's physics state.

For example

Your position on your device : 15,25
Your position on server : 20,25

In this case you need reset your position on your device with the one in server.
Now your position

Your position on your device : 20,25
Your position on server : 20,25

Now its synced

But there is a demerit to this method ,You will see your player getting teleported and jitters in movement and with high latency/ping it will get even worse.
To Fix jittery movements you need to implement Client-Side Prediction and Server Reconciliation.

You can learn it here : site1 and site2

Feel free to ask more, Actually i did not see my mail that's why it took too long to respond.

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.