3
\$\begingroup\$

I am experimenting with some simple multiplayer/networking in unity. Currently I have a plane object as the ground, and a cube prefab as the player object. I have a network manager with round-robin spawn and the built-in HUD. The cube has simple movement control (up/down is forward/backward, left/right turns the cube).


I can successfully start a game, build it, and add a client from the built app. However, when movement gets sent over the wire, the non-local player cubes in the game appear to "tilt forward," seemingly from the drag that the cube creates against the plane while moving. Strangely, when moving the local cube, no such tilt is experienced.



Here is a gif which illustrates:

dragging issue

In the above gif, the cube being moved is in the foreground window. Notice how the cube is only tilting in the other window.

Here is Update function of the Cube controller script:

// Update is called once per frame
    void Update () {

        // Change translation
        float moveAmount = CrossPlatformInputManager.GetAxis("Vertical");
        Vector3 deltaTranslation = transform.position + transform.forward * movementSpeed * moveAmount * Time.deltaTime;
        localRigidBody.MovePosition (deltaTranslation);

        // Change rotation
        float turnAmount = CrossPlatformInputManager.GetAxis("Horizontal");
        Quaternion deltaRotation = Quaternion.Euler (turnSpeed * new Vector3 (0, turnAmount, 0) * Time.deltaTime);
        localRigidBody.MoveRotation (deltaRotation * localRigidBody.rotation);

        MoveCamera();

    }

The ground is a plane with a rigid body and doesn't have a network identity or transform.

How do I stop the dragging from occurring and have the behavior be consistent across both instances of the game?

The full code to this project as it is right now is here: https://github.com/andyperlitch/blocks-multiplayer

Thanks!

\$\endgroup\$
  • \$\begingroup\$ You should add the relevant code to your question directly instead of linking to a github repo, since links die. \$\endgroup\$ – Tyyppi_77 Nov 12 '17 at 11:57
  • \$\begingroup\$ @Tyyppi_77 good point. I have added the relevant Update function. Thanks for looking.. \$\endgroup\$ – AndyPerlitch Nov 12 '17 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.