- Home /
How to use RPC functions to animate other players
How would i go about using RPCs to make other players animate when theyre walking, jumping, and idle, etc :P
Really curious. If someone could help thatd be great. Any code preferred in C# but not detremental :))
I solved the problem generically in my asset store package: https://www.assetstore.unity3d.com/#/content/13867 . All animations from all actors are being automatically synchronized across the network if you wish so.
nice asset :) although, id like to script it myself :P not use assets :))
I understand. The non-generic way would be to do sth like this:
$$anonymous$$ake a function in a script on your character
[RPC]
public void netWalk() {
animation.CrossFade("walking");
}
So ins$$anonymous$$d of just saying animation.CrossFade("walking") you would call that function with
netwokView.RPC("netWalk",RPC$$anonymous$$ode.All);
Then the function should be executed on all clients (and the server). I have not tested the code just now, but that's about how it can be made to work.
Answer by whydoidoit · Mar 11, 2014 at 09:46 AM
I wrote an article that has the basis of this principle: http://unitygems.com/weak-associations-leak-free-extension-properties/
nice article, ive started reading :)) it looks complicated though ughh
It is a bit complicated - but you can download the weak table stuff and use the example which sends animation data over Unity networking.
how could i implement it to this script. I wrote this a few nights ago, knowing nothing about RPCs so i knew it wouldnt work..
public float stopAnimation = 0.5f;
void Update ()
{
var directionVector = new Vector3 (Input.GetAxis ("Horizontal"), 0, Input.GetAxis ("Vertical"));
if (networkView.is$$anonymous$$ine) {
if (Input.GetButton ("Jump")) {
this.animation.CrossFade ("manP_jump");
} else {
if ((directionVector.x > stopAnimation || directionVector.x < -stopAnimation) ||
(directionVector.y > stopAnimation || directionVector.y < -stopAnimation) ||
(directionVector.z > stopAnimation || directionVector.z < -stopAnimation)) {
networkView.RPC("NetworkRun", RPC$$anonymous$$ode.All);
} else {
networkView.RPC("NetworkIdle", RPC$$anonymous$$ode.All);
}
}
}
}
[RPC]
public void NetworkRun ()
{
animation.CrossFade ("manP_run");
}
[RPC]
public void NetworkIdle ()
{
animation.CrossFade ("manP_idle");
}
i have got it to work yet it is leaking the data :/ hmm
Ok what it does is takes the animation on one character and sends it across the network. So you don't really send each one.
The idea is that you call SendAnimation regularly using InvokeRepeating or a coroutine (perhaps a a few times a second, and then only if something has changed). It calls the ReceiveAnimations across the network which then plays them all.
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Animation over network using rpcs 0 Answers
PhotonView over GameObject 2 Answers