0 votes

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

asked Apr 4 in Engine by Krippi (104 points)

1 Answer

+1 vote
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
answered Apr 5 by supper_raptor (719 points)
selected Apr 5 by Krippi

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 How to use this Q&A? before posting your first questions.