I am trying to make a network game and right now I am stuck on the animations. I am using a basic animation script for each player but when I move it animates both players but when someone else moves they are stuck with an idle animation.
I am pretty new to Unity and I am not really sure how I should go about fixing this. I found this little snipped below but I am not really sure how I would implement it. Any help would be very appreciated.
You can make a network animation script which is serializes only a single char variable, and then in the animation script you send a message to this network script and tell it what the current animation state is.
Ok, I figured out what was wrong with the animations. I set a network view and had it watch animations.
Now my main question is how could I implement the network animation script that would just tell what animation you are using instead of network view method. And is it a big difference in the amount of data being transmitted over the network?
uh. network views are done in c++ so most likely faster on client and server side and I really doubt there is much else sent besides what you need for it to observe an object and have is synchronize over multiple views.
Here’s an example ripped from the game I’m currently working on:
public var charMesh : Animation;
public var animations : Array = new Array();
animations[0] = "idle";
animations[1] = "walking";
private var currentAnimation : String;
function Start() {
charMesh.animation.Stop();
charMesh.animation.wrapMode = WrapMode.Loop;
charMesh.animation["walking"].layer = 1;
}
function setAnimation(aState:String) {
//Debug.Log("setting animation state:"+aState);
if(networkView.isMine) {
if(currentAnimation != aState) {
var aName : String;
for(var i=0; i<animations.length; i++) {
if(animations[i] == aState) {
networkView.RPC("setAnimationState", RPCMode.Others, i);
setAnimationState(i);
currentAnimation = aState;
return;
}
}
}
}
}
@RPC
function setAnimationState(aStateIndex : int) {
//Debug.Log("setAnimationState called with index:"+aStateIndex);
charMesh.animation.CrossFade(animations[aStateIndex], 0.2);
}
Basically all that does is store an array of possible animation names and play whichever one we tell it to, by using it’s index in the array. To use in a game you’d just call setAnimation(“walking”), which then calls the RPC and sends “1” as the parameter, which tells the remote character/whatever to play the animation name found at index 1 in the array.
To use it attach it to a gameObject with a networkView, set the networkView to no sync, and the observed property to reference the script. Fill in the references for charMesh and you should be good to go. You’ll need to edit the array in code (though that can easily be changed to be editable in the inspector).
i’ve had some problem with the example C# synch anim script from unity. it works properly, but i can only synch one animation at the time. i cannot play 2 simultaneously for the same object(delays one of the animations). must i split up the animation container and seperate animations to send them seperatly, or can i somehow use rpc and send both simultaneously ? (using mixedtransform to animate seperate bodyparts as the char walk/runs etc)
Use multiable states in that case or put those animations on a higher level that you want to override.
walk layer 1 //(playmode loop)
fire layer 4 //(playmode once)
If you call fire it will play that animation untill its finished then continue walk and if you use the mixingtrasform you can have fire control the upperbody wile its still walking with the lowerbody.
i’ve tried that with the Layers. but i can only have 1 “active” animation state. so yea, using multiple states would be the solution. or if i just seperate the animation into groups. The problem is that im inexperienced in this sort of scripting…
thanks for your time…