- Home /
Multiplayer animation only visible for my character
I've got a working multiplayer game, tried it when i turn it on from my pc and from a friend's pc. everything was working fine, except that the animations were only playing for my character. i have them in a script that makes them play when i press/release a button, but it has a NetworkView.isMine on it so that i don't trigger the other player's animations myself
any way to fix this?
#pragma strict
//var character : GameObject;
private var moveDirection : Vector3 = Vector3.zero;
var speed : float = 6.0;
var cam : GameObject;
function Start()
{
if (!networkView.isMine) // if this is not my player, remove the camera
Destroy(cam);
}
function Update () {if(networkView.isMine){
if(Input.GetKeyUp(KeyCode.W)||Input.GetKeyUp(KeyCode.A)||Input.GetKeyUp(KeyCode.S)||Input.GetKeyUp(KeyCode.D))
animation.CrossFade("idle");
if (Input.GetButtonDown("Fire1"))
{
//Attack animation - IF YOU ARE GETTING ERRORS BECAUSE YOU HAVENT MADE AN ANIMATION AND ATTACHED IT, DELETE THE FOLOWING LINE.
animation.CrossFade("punch");
}
if (Input.GetButtonDown("Fire2"))
{
//Attack animation - IF YOU ARE GETTING ERRORS BECAUSE YOU HAVENT MADE AN ANIMATION AND ATTACHED IT, DELETE THE FOLOWING LINE.
animation.CrossFade("attack3");
}
if (Input.GetKey(KeyCode.W)||Input.GetKey(KeyCode.A)||Input.GetKey(KeyCode.D)||Input.GetKey(KeyCode.S))
{
//Attack animation - IF YOU ARE GETTING ERRORS BECAUSE YOU HAVENT MADE AN ANIMATION AND ATTACHED IT, DELETE THE FOLOWING LINE.
animation.CrossFade("walk");
}
if(Input.GetKeyDown(KeyCode.Space))
animation.CrossFade("jump");
}
}
Answer by HarryGodden · Sep 02, 2014 at 12:26 PM
The animation does not get sent over the network automatically so you will need to send a RPC call, telling the other clients that an animation is in need of being played. I have modified the script for you here but I don't know much JavaScript so there may be some syntax errors.
#pragma strict
//var character : GameObject;
private var moveDirection : Vector3 = Vector3.zero;
var speed : float = 6.0;
var cam : GameObject;
function Start()
{
if (!networkView.isMine) // if this is not my player, remove the camera
Destroy(cam);
}
function Update ()
{
if(networkView.isMine)
{
if(Input.GetKeyUp(KeyCode.W)||Input.GetKeyUp(KeyCode.A)||Input.GetKeyUp(KeyCode.S)||Input.GetKeyUp(KeyCode.D))
networkView.RPC("IdleAnimation", RPCMode.All);
if (Input.GetButtonDown("Fire1"))
{
//Attack animation - IF YOU ARE GETTING ERRORS BECAUSE YOU HAVENT MADE AN ANIMATION AND ATTACHED IT, DELETE THE FOLOWING LINE.
networkView.RPC("PuchAnimation", RPCMode.All);
}
if (Input.GetButtonDown("Fire2"))
{
//Attack animation - IF YOU ARE GETTING ERRORS BECAUSE YOU HAVENT MADE AN ANIMATION AND ATTACHED IT, DELETE THE FOLOWING LINE.
networkView.RPC("Attack3Animation", RPCMode.All);
}
if (Input.GetKey(KeyCode.W)||Input.GetKey(KeyCode.A)||Input.GetKey(KeyCode.D)||Input.GetKey(KeyCode.S))
{
//Attack animation - IF YOU ARE GETTING ERRORS BECAUSE YOU HAVENT MADE AN ANIMATION AND ATTACHED IT, DELETE THE FOLOWING LINE.
networkView.RPC("WalkAnimation", RPCMode.All);
}
if(Input.GetKeyDown(KeyCode.Space))
networkView.RPC("JumpAnimation", RPCMode.All);
}
}
@RPC //IDLEANIMATION RPC
function IdleAnimation ()
{
animation.CrossFade("idle");
}
@RPC //PUNCHANIMATIONRPC
function PunchAnimation ()
{
animation.CrossFade("punch");
}
@RPC //ATTACK3ANIMTION RPC
function Attack3Animation ()
{
animation.CrossFade("attack3");
}
@RPC //WALK ANIMATION RPC
function WalkAnimation ()
{
animation.CrossFade("walk");
}
@RPC //JUMP ANIMATION RPC
function JumpAnimation ()
{
animation.CrossFade("jump");
}
My modifications should send the animation triggers over the network. Hope this helps, -Harry Godden :-)
well i replaced the script, built the game and when i run 2 of it, i can see the animation. i haven't tried with someone who has a different IP, but i'm guessing that it's gonna work. thanks
Your answer
Follow this Question
Related Questions
Animation synchronization in multiplayer setting 0 Answers
Simple Multiplayer Animation Question 1 Answer
FPS Multiplayer character animation / behaviour 0 Answers
How i can setup Character 0 Answers