Rigidbody physics buggy in editor with build open

Sorry for the long title. So I’m building a multiplayer third person shooter, and I added a script for the player to have a jetpack function. I have my networking set up fine (as far as I can tell) and most movements work fine across the server. I’m building on top of the Standard Assets Third Person Controller, and the movements from that also sync fine across the server.

My problem is that if I have the Editor running and a build open at the same time to test LAN, if I activate the Jetpack function, it runs fine in the build window, but if I use it in the Editor, it gets really buggy and the rigidbody tries to fight against the movement I’m applying to it from my script. It works fine in the Editor if I don’t have a build open, and it works fine if I have two instances of the build open, as well. I kind of hate the Editor sometimes. :slight_smile:

I’ve included the script here below. Am I missing something silly in regards to rigidbodies on networks? I tried inheriting this script from both monobehaviour and networkbehaviour, but that didn’t seem to make a difference (and I didn’t expect it to considering the third person controller is still a monobehaviour). Thanks for any help.

-Alex

using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;
using UnityEngine.Networking;

public class Jetpack : NetworkBehaviour {
    //[SerializeField] private float m_MinDropHeight = 1;
    public float m_FlyVerticalSpeed = 0.1f;
    [SerializeField] Vector3 maxLiftForcePerSec;
    [SerializeField] Vector3 maxLiftforceWhenDropping;
    private Vector3 actualLiftForcePerSec = Vector3.zero;
    private ThirdPersonCharacter controller;

    private bool wasInUseLastFrame = false;

    public float energyUsePerSec;
    private BackpackEnergy energyHandler;

    private void Start(){
        controller = GetComponent<ThirdPersonCharacter> ();
        energyHandler = GetComponent<BackpackEnergy> ();
    }

    private bool CanStartAbility(){
        if (!wasInUseLastFrame && energyHandler.getEnergy() < 15f)
            return false;
        return(energyHandler.getEnergy() > 0f && !controller.isGrounded());
    }

    //apply any movement
    void Update(){
        if (!isLocalPlayer)
            return;
        if (Input.GetButton ("Jetpack")) {
            if (!CanStartAbility ()) {
                wasInUseLastFrame = false;
                energyHandler.enableRegen = true;
                return;
            }

            energyHandler.enableRegen = false;

            //fill in audio stuff later
            if (wasInUseLastFrame)
                //print ("Jetpack on");

            if (controller.m_Rigidbody.velocity.y <= 0) {
                actualLiftForcePerSec = maxLiftforceWhenDropping;
            } else {
                actualLiftForcePerSec = maxLiftForcePerSec;
            }

            wasInUseLastFrame = true;
            controller.m_Rigidbody.AddForce (actualLiftForcePerSec * Time.fixedDeltaTime, ForceMode.Acceleration);

            energyHandler.CmdChangeEnergy (-energyUsePerSec * Time.deltaTime);
        } else {
            wasInUseLastFrame = false;
            energyHandler.enableRegen = true;
        }
    }
}

Well, I did a dumb. Turns out I should have been using FixedUpdate() instead Update(). I think I fixed it…