syncing animations

ok i need help with my animations the first player joins and all the animations work fine then when second player joins he is forever in the falling animation any idea how this is hapening? this is what i use to make the animations go
using UnityEngine;
using System.Collections;

public class amiwalking : MonoBehaviour {
	Animator anim;
	PlayerMovement Variables;
		
		void Start ()
		{
		GameObject Player = GameObject.Find("PlayerController(Clone)");
			Variables = Player.GetComponent<PlayerMovement>();
			anim = GetComponentInChildren<Animator>();
		}
	
	 //Update is called once per frame
	void Update () 
	{

						if (Input.GetButtonDown ("Vertical")) {
								anim.SetBool ("Walking", true);
						}

						if (Input.GetButtonUp ("Vertical")) {
								anim.SetBool ("Walking", false);
						}

	
						if (Input.GetButtonDown ("Run")) {
								anim.SetBool ("Running", true);
						}
		
						if (Input.GetButtonUp ("Run")) {
								anim.SetBool ("Running", false);
						}
	

						if (Variables.grounded == false) {
								anim.SetBool ("Jumping", true);
						}
						if (Variables.grounded == true) {
								anim.SetBool ("Jumping", false);
						}
				
		


	}


}




and this is my player manager

using UnityEngine;
using System.Collections;

public class NetworkCharacter : Photon.MonoBehaviour {

	Vector3 realPosition = Vector3.zero;
	Quaternion realRotation = Quaternion.identity;


	Animator anim;

	bool gotFirstUpdate = false;

	// Use this for initialization
	void Start () {
		CacheComponents();
	}

	void CacheComponents() {
		if(anim == null) {
			anim = GetComponent<Animator>();
			if(anim == null) {
				Debug.LogError ("ZOMG, you forgot to put an Animator component on this character prefab!");
			}
		}

		// Cache more components here if required!
	}
	
	// Update is called once per frame
	void Update () {
		if( photonView.isMine ) {
			// Do nothing -- the character motor/input/etc... is moving us
		}
		else {
			transform.position = Vector3.Lerp(transform.position, realPosition, 0.1f);
			transform.rotation = Quaternion.Lerp(transform.rotation, realRotation, 0.1f);

		}
	}

	public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
		CacheComponents();

		if(stream.isWriting) {
			// This is OUR player. We need to send our actual position to the network.

			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
			stream.SendNext(anim.GetBool("Idle"));
			stream.SendNext(anim.GetBool("Walking"));
			stream.SendNext(anim.GetBool("JumpingIdle"));
			stream.SendNext(anim.GetBool("Running"));
			stream.SendNext(anim.GetBool("JumpingWalking"));
			stream.SendNext(anim.GetBool("JumpingRunning"));
		}
		else {
			// This is someone else's player. We need to receive their position (as of a few
			// millisecond ago, and update our version of that player.

			// Right now, "realPosition" holds the other person's position at the LAST frame.
			// Instead of simply updating "realPosition" and continuing to lerp,
			// we MAY want to set our transform.position to immediately to this old "realPosition"
			// and then update realPosition


			realPosition = (Vector3)stream.ReceiveNext();
			realRotation = (Quaternion)stream.ReceiveNext();
			anim.SetBool("Walking", (bool)stream.ReceiveNext());
			anim.SetBool("JumpingIdle", (bool)stream.ReceiveNext());
			anim.SetBool("Running", (bool)stream.ReceiveNext());
			anim.SetBool("Idle", (bool)stream.ReceiveNext());
			anim.SetBool("JumpingWalking", (bool)stream.ReceiveNext());
			anim.SetBool("JumpingRunning", (bool)stream.ReceiveNext());
			if(gotFirstUpdate == false) {
				transform.position = realPosition;
				transform.rotation = realRotation;

				gotFirstUpdate = true;
			}

		}

	}
}





and my network manager

using UnityEngine;
using System.Collections.Generic;

public class NetworkManager : MonoBehaviour {

	public GameObject standbyCamera;
	SpawnSpot[] spawnSpots;

	public bool offlineMode = false;

	bool connecting = false;

	List<string> chatMessages;
	int maxChatMessages = 5;

	public float respawnTimer = 0;

	bool hasconnected = false;

	// Use this for initialization
	void Start () {
		spawnSpots = GameObject.FindObjectsOfType<SpawnSpot>();
		PhotonNetwork.player.name = PlayerPrefs.GetString("Username", "Awesome Dude");
		chatMessages = new List<string>();
	}

	void OnDestroy() {
		PlayerPrefs.SetString("Username", PhotonNetwork.player.name);
	}

	public void AddChatMessage(string m) {
		GetComponent<PhotonView>().RPC ("AddChatMessage_RPC", PhotonTargets.AllBuffered, m);
	}

	[RPC]
	void AddChatMessage_RPC(string m) {
		while(chatMessages.Count >= maxChatMessages) {
			chatMessages.RemoveAt(0);
		}
		chatMessages.Add(m);
	}

	void Connect() {
		PhotonNetwork.ConnectUsingSettings( "alpha" );
	}
	 
	void OnGUI() {
		GUILayout.Label( PhotonNetwork.connectionStateDetailed.ToString() );

		if(PhotonNetwork.connected == false && connecting == false ) {
			// We have not yet connected, so ask the player for online vs offline mode.
			GUILayout.BeginArea( new Rect(0, 0, Screen.width, Screen.height) );
			GUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();
			GUILayout.BeginVertical();
			GUILayout.FlexibleSpace();

			GUILayout.BeginHorizontal();
			GUILayout.Label("Username: ");
			PhotonNetwork.player.name = GUILayout.TextField(PhotonNetwork.player.name);
			GUILayout.EndHorizontal();

			if( GUILayout.Button("Single Player") ) {
				connecting = true;
				PhotonNetwork.offlineMode = true;
				OnJoinedLobby();
			}

			if( GUILayout.Button("Multi Player") ) {
				connecting = true;
				Connect ();
			}

			GUILayout.FlexibleSpace();
			GUILayout.EndVertical();
			GUILayout.FlexibleSpace();
			GUILayout.EndHorizontal();
			GUILayout.EndArea();
		}

		if(PhotonNetwork.connected == true && connecting == false) {

			if(hasconnected) {
				// We are fully connected, make sure to display the chat box.
				GUILayout.BeginArea( new Rect(0, 0, Screen.width, Screen.height) );
				GUILayout.BeginVertical();
				GUILayout.FlexibleSpace();

				foreach(string msg in chatMessages) {
					GUILayout.Label(msg);
				}

				GUILayout.EndVertical();
				GUILayout.EndArea();
			}
			else {
				// Player has not yet selected a team.

				GUILayout.BeginArea( new Rect(0, 0, Screen.width, Screen.height) );
				GUILayout.BeginHorizontal();
				GUILayout.FlexibleSpace();
				GUILayout.BeginVertical();
				GUILayout.FlexibleSpace();
				

				
				if( GUILayout.Button("Spawn!") ) {
					SpawnMyPlayer();
				}
				
				GUILayout.FlexibleSpace();
				GUILayout.EndVertical();
				GUILayout.FlexibleSpace();
				GUILayout.EndHorizontal();
				GUILayout.EndArea();


			}

		}

	}

	void OnJoinedLobby() {
		Debug.Log ("OnJoinedLobby");
		PhotonNetwork.JoinRandomRoom();
	}

	void OnPhotonRandomJoinFailed() {
		Debug.Log ("OnPhotonRandomJoinFailed");
		PhotonNetwork.CreateRoom( null );
	}

	void OnJoinedRoom() {
		Debug.Log ("OnJoinedRoom");

		connecting = false;
		//SpawnMyPlayer();
	}

	void SpawnMyPlayer() {
		hasconnected = true;
		AddChatMessage("player Joind: " + PhotonNetwork.player.name);

		if(spawnSpots == null) {
			Debug.LogError ("WTF?!?!?");
			return;
		}

		SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
		GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
		standbyCamera.SetActive(false);

		//((MonoBehaviour)myPlayerGO.GetComponent("FPSInputController")).enabled = true;
		((MonoBehaviour)myPlayerGO.GetComponent("MouseLook")).enabled = true;
		((MonoBehaviour)myPlayerGO.GetComponent("PlayerMovement")).enabled = true;
		((MonoBehaviour)myPlayerGO.GetComponent("amiwalking")).enabled = true;
		((MonoBehaviour)myPlayerGO.GetComponent("EnableandDisableMouse")).enabled = true;

		myPlayerGO.transform.FindChild("Resources/python/hips/spine/chest/chest-1/neck/head/Main Camera").gameObject.SetActive(true);
		//myPlayerGO.transform.FindChild("Main Camera").gameObject.SetActive(true);
	}

	void Update() {
		if(respawnTimer > 0) {
			respawnTimer -= Time.deltaTime;

			if(respawnTimer <= 0) {
				// Time to respawn the player!
				SpawnMyPlayer();
			}
		}
	}
}

Comments

  • Realy noone knows?
  • Sorry. Can't debug those scripts at the moment.
    If the animation is not OK, then check what's the state and where it should be set. Check if the relevant scripts are enabled to send the state and to apply it. Add debug log at places that should be called to check if they are.
  • the animations work fine but only on player one
  • also ill add when i add a new animation state it moves the player to 000 for some reason
  • Sorry but I can't really help with that. If you can't find out what is setting your states and or animations, then you might want to ask in the Unity forum, too.
    This is not really a networking issue. It's about using the values you sent and applying them in a manner that Unity can make sense of.

    Did you get closer to a solution by adding logs?