Network animations playing on all player models whenever any player moves.
I'm working on a multiplayer game and I have a animation manager that sends RPC's to all the players telling them to play the walking and idle animations on the player that called it, it's not working though. Whenever any player moves all of the players play the walking animation instead of just the person walking. If you guys could help me with this I'd owe you a solid.
#pragma strict
var anim : Animation;
function Start()
{
}
function Update ()
{
if(GetComponent.<NetworkView>().isMine)
{
if(Input.GetKeyUp(KeyCode.W)||Input.GetKeyUp(KeyCode.A)||Input.GetKeyUp(KeyCode.S)||Input.GetKeyUp(KeyCode.D))
GetComponent.<NetworkView>().RPC("IdleAnimation", RPCMode.All);
// if (Input.GetButtonDown("Fire1"))
// {
//Attack animation
// networkView.RPC("PuchAnimation", RPCMode.All);
// }
// if (Input.GetButtonDown("Fire2"))
// {
//Attack animation
// networkView.RPC("Attack3Animation", RPCMode.All);
}
if (Input.GetKey(KeyCode.W)||Input.GetKey(KeyCode.A)||Input.GetKey(KeyCode.D)||Input.GetKey(KeyCode.S))
{
//Attack animation
GetComponent.<NetworkView>().RPC("WalkAnimation", RPCMode.All);
}
if(Input.GetKeyDown(KeyCode.Space))
GetComponent.<NetworkView>().RPC("JumpAnimation", RPCMode.All);
}
@RPC //IDLEANIMATION RPC
function IdleAnimation ()
{
GetComponent.<Animation>().CrossFade("Idle");
}
// @RPC //PUNCHANIMATIONRPC
// function PunchAnimation ()
// {
// animation.CrossFade("punch");
// }
// @RPC ATTACK3ANIMTION RPC
// function Attack3Animation ()
// {
// animation.CrossFade("attack3");
// }
@RPC //WALK ANIMATION RPC
function WalkAnimation ()
{
GetComponent.<Animation>().CrossFade("Walk");
}
@RPC //JUMP ANIMATION RPC
function JumpAnimation ()
{
GetComponent.<Animation>().CrossFade("jump");
}
Answer by Wolfrik_Creations · Nov 29, 2015 at 01:37 AM
Correct me if I'm wrong but it looks like your other functions are a part of the Update function but I may just be crazy. Here I wrote a code that should work for you, but you will need to create an animation for walking left, right, and backwards if that's not too much trouble. If so I can remake another script.
#pragma strict
function Start () {
GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);
}
function Update () {
if(GetComponent.<NetworkView>().isMine){
if(Input.GetKey(KeyCode.W)) {
GetComponent.<NetworkView>().RPC("WalkAnim", RPCMode.All);
}
if(Input.GetKey(KeyCode.Space)) {
GetComponent.<NetworkView>().RPC("Jump", RPCMode.All);
}
if(Input.GetKeyUp(KeyCode.W)) {
GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);
}
if(Input.GetKey(KeyCode.A)) {
GetComponent.<NetworkView>().RPC("StrafingLeftF", RPCMode.All);
}
if(Input.GetKeyUp(KeyCode.A)) {
GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);
}
if(Input.GetKey(KeyCode.D)) {
GetComponent.<NetworkView>().RPC("StrafingRightF", RPCMode.All);
}
if(Input.GetKeyUp(KeyCode.D)) {
GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);
}
if(Input.GetKey(KeyCode.S)) {
GetComponent.<NetworkView>().RPC("WalkingBackwards", RPCMode.All);
}
if(Input.GetKeyUp(KeyCode.S)) {
GetComponent.<NetworkView>().RPC("Idle", RPCMode.All);
}
if(Input.GetMouseButtonDown(0)) {
//ATTACK ANIM HERE
}
}
else{enabled=false;}
}
@RPC
function Idle () {
idle=false;
GetComponent.<Animation>().CrossFade("Idleation");
}
@RPC
function Jump () {
GetComponent.<Animation>().CrossFade("jump");
yield WaitForSeconds(1);//YOUR JUMP TIME IN THOSE PARENTHESES
GetComponent.<Animation>().CrossFade("Idle");
}
@RPC
function WalkingBackwards () {
GetComponent.<Animation>().CrossFade("WalkingBack");
}
@RPC
function WalkAnim () {
GetComponent.<Animation>().CrossFade("Walking");
}
@RPC
function StrafingLeftF () {
GetComponent.<Animation>().CrossFade("StrafingLeft");
}
@RPC
function StrafingRightF () {
GetComponent.<Animation>().CrossFade("StrafingRight");
}
@RPC
function PunchAnim () {
//MAKE THE PUNCH ANIM RUN AN RPC TO THIS
}
If you don't want to use this I'm pretty sure the problem is that you need to have after your GetComponent..isMine you need to put else{enabled=false;}
also if I were you I'd use GetMouseButtonDown(0) rather than GetButtonDown("fire1")
:D
Also if you have any questions you can add my Skype israel.boone1 because I'm experienced with JS and a bit of C# but I'm also learning multiplayer right now and can help you with any problems you have. :D
Your answer
Follow this Question
Related Questions
Help with bullet going in the dirrection fired from view of camera?? 1 Answer
Setting function to run on all clients but only work on the player that called it 0 Answers
UNET: Network [Command] from non-player object 0 Answers
Player attacking enemy script 0 Answers
I want my character to enter and exit car with animation 1 Answer