#"Hindered" State and Client Prediction / Reconcile

6 messages · Page 1 of 1 (latest)

rigid quarry
#

Fishnet Version: 4.7.1R from Package Manager. Unity Version 600.4.0f1.

I have a question I would like to have confirmed properly.

Imagine a player with an ability that has a trigger. For simplicity, let's say he has a box in front of him. Any other players touching that trigger should get completely disabled - they shouldn't be able to move or do anything else.

For this, i've added a NetworkBehaviour called "HinderedState" to the player(s). That HinderedState has a SyncVar<bool> that gets set by the server when a client enters that trigger. I think this is where i went wrong.

When moving the player using runinputs and reconcile, that hinderedState is now not in the prediction / reconcile loop, meaning that when the client replays the last few ticks after a reconcile (if i understood correctly) it has HinderedState to true even though it should have been set to false in the last few ticks, right? Here's some pseudocode:

[Replicate]
private void RunInputs(....){
if (_hinderedState != null && _hinderedState.IsHindered)
{
_predictionRigidbody.Simulate();
return;
}
//Other stuff like activating abilities / simulating the rigidbody etc.
}

If this is the problem and I've understood everything correctly, I should add the hinderedState to my CreateReplicateData, right? But as that runs every tick, do I just poll the trigger? If then that trigger were to turn off / move in and out of the client etc. wouldn't that lead to jitter again?

I'm not sure I understood everything correctly and would be very appreciative of some help 😄 Thanks!

jagged patrol
#

Hey there, you're absolutely correct about it, using a SyncVar isn't part of the prediction loop and will thus cause problems. You'll want to use a NetworkTrigger instead or even a normal trigger collider with OnTriggerStay and check the state inside the prediction cycle

#

If handled correctly it shouldn't cause any jitter

rigid quarry
#

Thanks for the response! I have three follow up questions that tie into the same system:

Does this mean that I also need to reconcile that value in addition to putting it into the replicate data?

Is using a raycast instead of networkcolliders (for example to detect if you are on a special collider) working with the prediction / reconcile system or not? When it resimulates, does everything still line up?

Additionally, am I right to assume that if I stop a rigidbody by setting its velocity to 0 that the discrepancy in the physics simulation from client to server (who sends a reconcile) causes it to move after the fact on the client? Trying to place that collider i said above exactly below the client when he clicks a button 🙂

jagged patrol
rigid quarry
#

I think it just clicked for me, thank you @jagged patrol. I made the mistake of sending state (like that an ability was started) over the runinput and reconcile methods instead of just input (the player pressed a button).

The last question was about a bit of a more complicated thing. When the client presses that ability, imagine a box being placed below the client (predictedspawn). Then, the server does the same thing. As its a predictedspawn, the location of the client will be in the wrong spot, so what I'll do is that the server just moves the predictedspawned box under the client that executed the ability, fixing the discrepancy.