In NetworkCharacterController (Fusion's sample code) why is Velocity and IsGrounded Networked?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Fusion.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

In NetworkCharacterController (Fusion's sample code) why is Velocity and IsGrounded Networked?

ueharajohji
2022-10-07 11:52:07

I am trying to learn photon fusion through the sample codes. I am just wondering why is there a need for IsGrounded and Velocity to be networked when the transform is already sent across the other players? Does it have something to do with client predictions and stuff?

Comments

emotitron
2022-10-08 14:02:55

Correct, the main reason typically for Networked values is for correct tick accuracy on clients and for client prediction.

Typically values are networked because they are considered "State", which for client prediction is important because these values need to correctly "rewind" during client reconciliation. The client needs to know when it is rewound what the exact server state was for that tick.

ueharajohji
2022-10-08 16:36:01

@emotitron Thanks for the clarification.

I am still reading tons of sample code and I think I am getting the grasps of networked variables.

I still haven't been able to wrap my head around this line

In my understanding the only variable that is affected by the networked "Velocity" is the horizontalVel which gets the x and y of the Velocity. The other variable that is going to change is direction which is controlled via **networkInputData.**Which i suspect can give a bug when a player is moving through stairs (or any uneven surface) with the code below.

Velocity = (transform.position - previousPos) * Runner.Simulation.Config.TickRate;

say for example a player is trying to walk into stairs which has a height that is too high for a player to walk into but walking into the edge of it is possible. this scenario might give the following result

Velocity = (1, 1.5, 1) - (1, 1.34, 1) * Runner.Simulation.Config.TickRate;

= (0, 9.6, 0)

which in this will make a player jump very high (this actually happens in fusion sample code, so I am just wondering if I am missing something or not).

emotitron
2022-10-08 18:51:07

I am not personally familiar enough with NCCP to comment, but someone else may who knows more about that implementation may chime in.

ueharajohji
2022-10-09 03:50:20

@emotitron Okay ! Thanks for sharing your thoughts!

Theoderek
2022-11-28 01:53:28

ueharajohji 2022-10-08T16:36:01+00:00

@emotitron Thanks for the clarification.

I am still reading tons of sample code and I think I am getting the grasps of networked variables.

I still haven't been able to wrap my head around this line

horizontalVel      = Vector3.ClampMagnitude(horizontalVel + direction * acceleration * deltaTime, maxSpeed);  

In my understanding the only variable that is affected by the networked "Velocity" is the horizontalVel which gets the x and y of the Velocity. The other variable that is going to change is direction which is controlled via networkInputData. Which i suspect can give a bug when a player is moving through stairs (or any uneven surface) with the code below.

Velocity = (transform.position - previousPos) * Runner.Simulation.Config.TickRate;

say for example a player is trying to walk into stairs which has a height that is too high for a player to walk into but walking into the edge of it is possible. this scenario might give the following result

Velocity = (1, 1.5, 1) - (1, 1.34, 1) * Runner.Simulation.Config.TickRate;

= (0, 9.6, 0)

which in this will make a player jump very high (this actually happens in fusion sample code, so I am just wondering if I am missing something or not).

Is there a solution to this? Because this happens to me all the time, the player bumps into something and goes flying into the air.

Back to top