Hello, I have a non-player character that gets spawned. I have a couple of animations that play properly and I just added some code for aiming at players, the code rotates the head and spine of the npc to aim directly at the first person camera of the player. Code (CSharp): private Transform lookObj; void Update() { if (lookObj != null) { return; } lookObj = GameObject.FindGameObjectWithTag("MainCamera").transform; Debug.Log(lookObj.name); } void OnAnimatorIK() { if (!anim) { return; } if (ikActive) { //lookObj is the Player camera if (lookObj != null) { anim.animator.SetLookAtWeight(1); anim.animator.SetLookAtPosition(lookObj.transform.position); Debug.Log("Head rotation set"); spineTransform = anim.animator.GetBoneTransform(HumanBodyBones.Spine); newRotation = Quaternion.LookRotation(lookObj.transform.position - spineTransform.position, Vector3.up); newRotation.y = newRotation.y - 0.2f; anim.animator.SetBoneLocalRotation(HumanBodyBones.Spine, newRotation); Debug.Log("Body rotation set"); } else { anim.animator.SetLookAtWeight(0); } } } Currently, as a new client joins, the camera is referenced correctly and the npc aims directly at the camera, however, the movement is only visible on the server side. The npc on the client side never gets the movement updates. I have a couple of theories for this. The first one, is that I'm referencing the camera instance on the server side, but not the camera instance on the client side, so the npc never gets updated. The second one is that IK and transforms that are made directly on the skeleton need to be send individually to each of the clients-- I don't know how to go about this. If any one has an idea of how to solve this, I appreciate the help!
It looks like what you have should run on both sides. Are you getting error messages about null references on the client? Are any of those log messages getting written on the client? The debugger should help you track down what's different.
When I have the Debug.Log("lookObj.name"); I get a "BaseObject: NotAvailableDuringDebugging" error in Visual Studio, but I don't think that is related to the synchronization. Other than that, no errors at all. I tried to run a standalone version of the app as a server and connect with the editor as a client to be able to see the errors directly in the editor, but the editor never connected, so I just moved on. Again, I think there is a problem with the client not referencing the camera properly, which is weird because the player is the one that spawns the camera in the first place, and until it spawns the server won't find a reference. As the client joins, the server gets the reference right away but not the client.
I built a clean scene with just my player and the npc to test this specific code and functionality and the synchronization worked properly. I'm not sure yet what I'm missing on my actual scene, maybe some of the other code that I have is the problem.
That code seems to be client side only. The lookObj needs to be synced properly on server and client for you to get your desired effect. Often, camera functionality is client side only, particularly if you are aiming weapons. So, if you are aiming a weapon. You want to sync a different object that is controlled by the client of the network. For instance, sync a target object that the camera is pointing at over the network.
Hi, thanks for chiming in. Actually this code works fine on server and client. In my case the camera is already being synced properly because it is part of the player prefab (a first person player), also, it's position is synchronized through the "Network Transform" component. Having said that, I found what my problem was, and it was actually very simple. My start method, where I get the reference to the Network Animator, had a [Server Callback] so it was only running on the server. Very silly mistake on my part, thanks everyone for the help!