Help With Network Animations
I am using Photonview for networking in my FPS. There is an FPS controller with the standard scripts, which has a 3d model that the other players would see. I disable this for the current player, and enable it for all other players. The problem is the mechanim animator is opposite what it should be. When Player A moves, it can see the animation play on Player B. Player B can see the animations on Player A. I had a similar issue with movement and rotation, but this was solved by disabling the camera and character controller script, and then enabling them in the Start() function for each player. This made sure each player could only control themselves and not the other players. I have tried a similar method of disabling the player prefab's animator component, and then enabling it in the Start() function, but the same issue happens.
Here is the function that spawns the player and enables/disables each component(animator, character controller, camera, etc) accordingly,located in room_manager.cs:
public void spawnPlayer()
{
GameObject pl = PhotonNetwork.Instantiate( playerPrefab.name, selectedSpawn.position, selectedSpawn.rotation, 0) as GameObject;
pl.GetComponent<CharacterControls>().enabled = true;
pl.GetComponent<CharacterControls>().fpsCam.SetActive(true);
pl.GetComponent<CharacterAnimController>().enabled = true;
pl.transform.GetChild(0).transform.GetChild(1).GetComponent<Renderer>().enabled = false;
}
Here is the code for controlling the animator, located in animcontroller.cs:
void Update() {
animController.SetFloat("Horizontal", Input.GetAxis("Horizontal"));
animController.SetFloat("Vertical", Input.GetAxis("Vertical"));
}
The code to control the animator works correctly, other than it animates the wrong player. I am sure the problem lies in enabling/disabling each animator component like it was with the camera and controller, but I cannot figure it out.
The layout of my player prefab is as follows:
PlayerA(has animator component with avatar set to avatar of body model, has script to update anim controller parameters based on player input)
Body Model(What other players see, this is disabled for the current player, has a photon view component observing its transform)
FPS Arms Object(the arms/gun the local player sees, is disabled for other players)