What is the proper way to AddForce in Fusion?
The whole answer can be found below.
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).
What is the proper way to AddForce in Fusion?
WARdd
2022-07-19 11:02:46
I'm building a game where player characters are controlled via Unity physics engine, each player has a NetworkRigidbody and player input is used to determine forces being applied to that rigidbody. I'm not certain what the proper approach here is for Fusion, since all examples I can find just set velocities or positions in FixedUpdateNetwork, but Unity wants you to use FixedUpdate for things like AddForce. Anyway, here's a pseudo code version of what I'm doing right now:
NetworkedRigidbody rb;
Vector3 movementInput;
Vector3 movement;
NetworkFixedUpdate(){
InputData input = GetInputViaNetworkedObjectDotGetInput();
movementInput = input.movement;
}
private void FixedUpdate() {
movement = UpdateMovementOverTime(movement, movementInput, Time.FixedDeltaTime);
rb.RigidBody.AddForce(movement, ForceMode.Force);
}
Anyway, what would this pseudo code look like in the proper Fusion approach? Should some of the variables be [Networked]? In particular "movement" would be subject to time-dependent evolution
Comments
I found an official Photon engine example, it seems they just go ahead and put regular AddForce calls in FixedUpdateNetwork. I'm not sure how that works with the time scale, since the deltatime can be 0, but it does seem to work fine as long as I'm careful with dividing by deltatime in my code.
Time varying variables like the movement vector in my example should definitely be networked, altough my use case is a bit more complex so I will have to work something out...
Back to top