- Home /
Question by
andonegr · Jun 10, 2015 at 07:17 PM ·
networkinganimatorrpc
rpc / head rotation
Hello,
I am trying to create a multiplayer game and i cannot get the head rotation updated on the network. I am using RPC's to update player position and rotation,as well as animations, as stated in other topics and everything works fine, but head looking is set On animator Ik and doesn't get updated. I tried attaching another network view that observes the head bone, as suggested elsewhere, and i am getting a trembling movement of the head on the network.
If anyone has any suggestions, thanks in advance. Here is an example of my code:
void OnAnimatorIK()
{
anim.SetLookAtPosition(lookatme.transform.position);
lookweight = Mathf.Lerp(lookweight,1f,Time.deltaTime*lookSmoother);
anim.SetLookAtWeight (lookweight);
}
void Update ()
{
if (GetComponent<NetworkView>().isMine) {
//If the player has moved at all then fire off an RPC to update the players
//position and rotation across the network.
if (Vector3.Distance (myTransform.position, lastPosition) >= 0.1) {
//Capture the player's position before the RPC is fired off and use this
//to determine if the player has moved in the if statement above.
lastPosition = myTransform.position;
GetComponent<NetworkView>().RPC ("updateMovement", RPCMode.OthersBuffered,
myTransform.position, myTransform.rotation);
}
if (Quaternion.Angle (myTransform.rotation, lastRotation) >= 1) {
//Capture the player's rotation before the RPC is fired off and use this
//to determine if the player has turned in the if statement above.
lastRotation = myTransform.rotation;
GetComponent<NetworkView>().RPC ("updateMovement", RPCMode.OthersBuffered,
myTransform.position, myTransform.rotation);
}
}
}
[RPC]
void updateMovement (Vector3 newPosition, Quaternion newRotation)
{
transform.position = newPosition;
transform.rotation = newRotation;
}
[RPC]
void SendFloat(string name, float value){
anim.SetFloat (name, value);
}
Comment