Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jeijei · Sep 02, 2014 at 10:15 AM · animationmultiplayercharactervisible

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");
         
     }
     }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer Wiki

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 :-)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jeijei · Sep 02, 2014 at 02:06 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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

Multiplayer FPS movement and animations character 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges