- Home /
Issues with using RPC calls for animations
I am currently using a range of tutorials to make a FPS multiplayer game. I cannot figure out why the animations aren't working considering the RPC's are getting called. There are two settings, crouching and standing for the player. The animation for crouching plays as well as standing, but not the animations such as walking. I've put breakpoints at the lines for where the walking/idle animations change and they are hit properly. The debug log is also displayed at the right time as well. All the animations are looped in start, their layers are -9.
Here are the RPC functions:
@RPC
function SendStance(charStance : String, info : NetworkMessageInfo)
{
stance = System.Enum.Parse(typeof(charStanceState), charStance);
}
@RPC
function SetDirectionState(directionState : String, info : NetworkMessageInfo)
{
Debug.Log("directionState is "+directionState);
dirState = System.Enum.Parse(typeof(charDirState), directionState);
}
Both are getting called in Update, whenever the state changes from the previous state. SetStance is for crouching/standing, whenever you hit the c button this switching the stance. SetDirectionState is for changing the direction at which the player is looking and UpdateAnimation crossfades to the corresponding animation.
function Update ()
{
SetStanceState();
if(prevStance != stance && networkView.isMine)
{
networkView.RPC("SendStance", RPCMode.OthersBuffered, stance.ToString());
prevStance = stance;
}
SetDirectionState();
if(prevDirState != dirState)
{
networkView.RPC("SetDirectionState", RPCMode.OthersBuffered, dirState.ToString());
prevDirState = dirState;
}
UpdateCharacterAnim();
}
If anyone has any suggestions on how to animate characters using RPC please comment or answer. Thank you very much in advance because I'm at my whit's end for this!
Here's a little of the UpdateAnimation function if it helps.
function UpdateCharacterAnim() : void { switch (dirState)
{
case charDirState.Idle: // The player is idle.
switch (stance)
{
case charStanceState.Standing:
characterAnimator.CrossFade(idleAnimString, .3);
break;
......... Again, I just don't understand why crouching animations work when walking animations are the same! They're triggered by a button just like crouch >_<
Answer by lizzyCTS · Oct 13, 2011 at 03:11 PM
I figured out the problem! For networking, you really really need to differentiate dummy characters from the main player. This was my function for SetDirection:
function SetDirectionState() : void
{ var charDir : Vector3 = characterInputCtrl.GetDirectionVector();
if (motor.canControl)
{
// Are we moving forward?
if (charDir.z > 0.1)
.... The dummy character was probably pretty confused by this considering I disabled the character motor! So, I made a boolean to check if this was a dummy character, then to execute those functions only in the RPC function, not every frame.