What is the proper way to AddForce in Fusion?

WARdd
WARdd ✭✭

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

Answers

  • WARdd
    WARdd ✭✭

    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...