Locomotion and Photon

Options
Hi,

I am working on a project that uses the locomotion system to animate my characters. Now what i need is i want to sync the character motor to display the correct animations when the remote character moves. This kinda works. However, the problem is that the animations look terrible, especialy when the "desiredMovementDirection" is 1.

My character's photon view settings are as followed:
-Opserve Option: ReliableDeltaCompression
- Serialization: PositionAndRotation.


I think that the animations are terrible because the photon view updates the player's position and rotation? How can i disable this, while remote players still move, and get this information from the character motor somehow?



This is my network script:
using UnityEngine;

using System.Collections;



public class ThirdPersonNetwork : Photon.MonoBehaviour

{



    MouseLookCharacterController controllerScript;

	FPSCharacterController fpsScript;

	CharacterMotor motorScript;



	public Camera camera;

    void Awake()

    {



        controllerScript = GetComponent<MouseLookCharacterController>();

		motorScript = GetComponent<CharacterMotor>();

		fpsScript = GetComponent<FPSCharacterController>();

		cameraScript = camera.GetComponent<CharacterOrbit>();

    }

    void Start()

    {

        //TODO: Bugfix to allow .isMine and .owner from Start!

        if (photonView.isMine)

        {

            //MINE: local player, simply enable the local scripts

            camera.enabled = true;

            controllerScript.enabled = true;

			controllerScript.isControllable = true;

			

			fpsScript.enabled = true;

			fpsScript.isControllable = true;

        }

        else

        {           

            camera.enabled = false;



            controllerScript.enabled = true;

            controllerScript.isControllable = false;

			

			fpsScript.enabled = true;

            fpsScript.isControllable = false;

			

        }



        gameObject.name = photonView.owner.name;



    }



    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)

    {

        if (stream.isWriting)

        {

            //We own this player: send the others our data

   

			stream.SendNext(motorScript.desiredFacingDirection);

			stream.SendNext(motorScript.desiredMovementDirection);

        }

        else

        {

            //Network player, receive data


			desiredFacingDirection = (Vector3)stream.ReceiveNext();

			desiredMovementDirection = (Vector3)stream.ReceiveNext();

        }

    }



    private Vector3 desiredFacingDirection = Vector3.zero; //We lerp towards this

    private Vector3 desiredMovementDirection = Vector3.zero; //We lerp towards this


	

	

    void Update()

    {

        if (!photonView.isMine)

        {

			motorScript.desiredFacingDirection = desiredFacingDirection;

			motorScript.desiredMovementDirection = desiredMovementDirection;

			

        }

    }



}

Comments

  • Tobias
    Options
    If you chose Serialization: PositionAndRotation, the view will only sync pos and rotation. Those will be applied more or less directly and your animations will constantly be broken by those updated. That's where the stuttering comes from.

    The Demo Worker (in the PUN package) shows how you serialize your own, custom information. In that, we sync a "character state", which could be replaced with your animation state.
  • Why is there a position and rotation update function inside the network script while the photon view already updates this?


    So when i have the locomotion system, the animations are done dynamically. So i cant just remotely control the character motor? How can i sync these animations?
  • Tobias
    Options
    > Why is there a position and rotation update function inside the network script while the photon view already updates this?
    A PhotonView can either sync position/rotation or call a script to provide the data to sync for each update. So, once the script is observed, the position and rotation are no longer synced.

    I don't know how the locomotion package works and I can't take the time to get into it at the moment. Sorry.

    You know that either just the position and rotation are synced OR some script is called to get some synchronization data. Try to find out which way fits better to your locomotion system and how to smooth out animations when you get updates.
  • Alright so,

    How do i add a network script to the photon view? As i can see i can only Add my player prefab to the "Opserve", not a script. The PUN example has the player attached, but not as transform. In that example i can see:

    Observe: (ThirdPersonNetwork) Player. So how is this added actualy? when i add my player to it, the "(ThirdPersonNetwork)" changes to "(UnityEngine.Transform)"

    Thanks
  • dreamora
    Options
    the same way you do it for unity networkviews. you drag the script in thats attached to a game object (you can drag the top area of the script block on the game object in the inspector)
  • HHm, i am not able to drag a script onto it. It simply displays the forbidden mouse cursor when i try to do that... Any idea ?

    Edit: aha i see, i need to drag from the inspector. Thanks!
  • dreamora
    Options
    ah should have been more specific. Right you drag the 'scripts header' from the inspector over the slot :)