-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Network] execute remote players' actions on client with no authority #44
Comments
Using booleans in the snapshot could be a solution. However I'm not entirely sure about how resilient it would be when packet loss occur. Since you are dealing with animations (and here I assume you are using the
Then, to increase the resilience an additional float can be used to indicate the playback position. The And to check if the correct animation is being played you can use |
Thanks for your reply! I see how sending the current animation data in the snapshot could help in the case of simple scenes: Though it would be quite cumbersome with a more complex scene: In this case, the entity attacking would play an attack animation and the weapon equipped would also play an attack animation. Meaning the weapon state/animation would need to be synchronized via snapshot as well. Ideally, the weapon would be synchronized only when the entity/player changes it, letting the other peers know about the current weapon. Also, another problem occurs when you want to add an attack combo, executing the attack id = 2 after the attack id = 1 if the action key is pressed again in a short period of time. I struggle to see how this kind of information could be passed to the other peers. Here is the solution I'm using, to help anybody who may need this in the future: Your answer pointed me in the right direction, but instead of sending the animation name and the animation time, I'm sending the "action state" of the entity: such as no_action (int = 10), attacking (int = 20), blocking (int = 30), etc. as well as an action_id, incrementing every time a new action is to be sent. I'm using a base 10 in my example, so that I can divide by 10 to get the action to execute and use the last digit (with a modulo) to "pass" an argument: for example the attack_id for a combo (20, 21, 22...) The client keeps in memory the last_action_id executed, as to not execute a second time the same action (since the snapshot are sent 60 times/sec, there are a lot of duplicate action/action_id). The physics_process() in the entity:
When the local player/server entities do an action, in this case an attack, update the variables sent in the snapshot (action, action_id):
|
That is a very interesting solution! It will work very well as long as you don't need to have 10+ attack IDs. Now bear in mind: I know it's a bit clunky to replicate game state rather than the inputs so the clients could calculate the result. When I designed the Addon I was too focused on the idea server does everything while clients "only" replicate the state of the game. I might review this design decision in the future. |
I will indeed use the integer divided into two parts as it's definitely cleaner, thanks for the suggestion! I definitely see where you are coming from by replicating the game state and not the inputs, either way, compromises have to be made and your addon already helps me a lot, so again, thanks for that! Using the method I described above, the action synchronization is working quite well, even though I still didn't really test on bad network conditions. But even on high latency, since the simulation/animations are running locally, only the starting point of these actions matters: when the client receives a snapshot containing a more recent action. |
Hello,
Say you have an action registered:
network.register_action("attack", false)
in the physics_process() of the player script, the code
input = network.get_input(_uid)
is only executed on the local machine and on the server:network.gd:
meaning a remote player scene will not be able to check and execute the
input.is_pressed("attack")
to play, for example, an attack animation.For now, the attack animation is played if the player is local and on the machine that has authority, but a client that doesn't have authority will not be able to execute actions of other players.
How would you go about synchronizing the actions of all players on all machines?
Same question goes for an NPC entity.
Would the solution be to put new booleans in the snapshot script extending
SnapEntityBase
, and set them asaction = true
when receiving a new action from the snapshot ?Thanks for the addons and for your help.
The text was updated successfully, but these errors were encountered: