- Home /
Simple Multiplayer Animation Question
Hello unity community iv made a little multiplayer game, my problem is that the other player cannot see my players animation, but i can?? and same with the other player, iv been trying to solve this for 4 straigt hour.
Anyways everything but THAT! works just fine.
can you guys help me?? Heres the AnimationScript:
#pragma strict
private var Soldier : Transform;
var animon = false;
function Start () {
Soldier = transform.FindChild("soldierNoScript");
if(networkView.isMine == true)
{
animon = true;
}
}
function Update () {
if (Input.GetAxis("Vertical") ||Input.GetAxis("Horizontal")){
if (animon == true){
Soldier.animation.CrossFade ("soldierWalk");
}
}
else
{
Soldier.animation.CrossFade ("soldierIdle");
}
}
Thanks in advance Guys ^^
I see no networking code... how do you think your animations will sync, if you haven't programmed them to sync?
Answer by darkcookie · Jul 31, 2013 at 12:40 PM
ok What you need to do is add a NetworkView component to the soldier and set its State Synchronization to Reliable Delta , and Observed to the animation component in the soldier . If you use mecanim then set one to view the animator and one to view the animation ,although i believe all u need is the animation one ....any ways ,you find this under Components/Miscellaneous/NetworkView
Good Luck:D
...ohhh a litle tip ..if your animation is located within the parent as a child u can right click the inspector tab and lock it...this allows you to open another inspector and still be able to drag and drop the animation component into "observed"
This is a method and it does work, however I recommend not using built-in synchronisation. It's not very optimised and usually syncs more data than needed :)
yh that's true but its the easiest way to do it if he plans on just testing his animations ...if not he could make an update script that sends and captures rpc's...
here i made U one that updates the players position ...just so u can get an idea on how to do RPC calls...add this to the player . prefab.
using UnityEngine;
using System.Collections;
public class $$anonymous$$ovementUpdate : $$anonymous$$onoBehaviour {
//Variables Start___________________________________
private Vector3 lastPosition;
private Quaternion lastRotation;
private Transform myTransform;
//Variables End_____________________________________
// Use this for initialization
void Start ()
{
if(networkView.is$$anonymous$$ine == true)
{
myTransform = transform;
//Ensure taht everyone sees the player at the correct location
//the moment they spawn.
networkView.RPC("update$$anonymous$$ovement", RPC$$anonymous$$ode.OthersBuffered,
myTransform.position, myTransform.rotation);
}
else
{
enabled = false;
}
}
// Update is called once per frame
void Update ()
{
//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 deter$$anonymous$$e if the player has moved in the if statement above.
lastPosition = myTransform.position;
networkView.RPC("update$$anonymous$$ovement", RPC$$anonymous$$ode.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 deter$$anonymous$$e if the player has turned in the if statement above.
lastRotation = myTransform.rotation;
networkView.RPC("update$$anonymous$$ovement", RPC$$anonymous$$ode.OthersBuffered,
myTransform.position, myTransform.rotation);
}
}
[RPC]
void update$$anonymous$$ovement (Vector3 newPosition, Quaternion newRotation)
{
transform.position = newPosition;
transform.rotation = newRotation;
}
transform.rotation = newRotation;
}
Hey guys my problem is that i'm not very experienced with the rpc thing, "darkcookie" good example but i'm just not getting it.. can anyone reply me the basics it would be great ^^
Your answer
Follow this Question
Related Questions
How i can setup Character 0 Answers
Animation does not work for the remote player 0 Answers
Multiplayer Walk animation playing for opposite person 0 Answers
Networking Animation problem 1 Answer
Network animations 2 Answers