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 vzdemon · Jun 04, 2012 at 11:45 AM · c#animationnetworksync

Sync Network Animation State

How do i go about having animations show in my online game. i have the same prefab for each player and you can only see thier position,rotation,scale but animations don't show over the network they only show localy on the client meaning each client can only see his own anitmation but not other's.

i've looked it up on the web and i found out that i need to make some kind of enum that will comtain the player's current animation and then broadcast it or something, it's called Network animation Sync if i'm not mistaken, but the problem is i have no idea of how to do that or how to it works.

if some1 could point me in the right direction or give me some kind of script it wouyld be wonderful.

thanks for reading. (BTW i'm using C#)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by toddisarockstar · Apr 24, 2015 at 08:06 PM

i asked this a while ago too. the answer is "you dont". lol 90% of the time its not nessessarry. each players script can determain for itself.

for example: your existing script can simply detect if a transform.position hasnt changed in a few frames. so your script can assume to trigger a "standing" animation without sync.

if transform.position HAS changed from the last frame your individual machines would each trigger its own "walk" animation without networkhelp.

if you send an rpc for an object to shoot something. then no need for an additional animation rpc. just trigger the "shoot" animation along with the shooting.

for unusual situations. you can always RPC the animation but even if you could "Sync" automatically it would clog precius bandwidth that you need for multiplayer.

these few extra lines of detection is far more efficient than clogging up your small precious bandwidth to sync a bunch of animations.

data proccessed through the internet is like a pinhole compareded to what any modern CPU can calculate. General rule for proficancy for online games is only send what you really have to!

actually this way looks smoother too. the couple frames delay it takes for a pc to figure out if a character is moving is a unnoticable fration of a second. its faster than the time it takes to get a data through the internet. there is no "lag".

but to reluctantly answer your question..... if you really really wanted a super slow laggy game you could stick seperate networkveiw components with state syncs on all the CHILD objects of your objects and this would actually sync your animations like are describing. you would just need on EVERY object part.

Comment
Add comment · 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
0

Answer by Mikdad_Merchant · Apr 24, 2015 at 07:46 PM

well in a game I was working on I just need to solve the same issue, this script is what is guiding me, this is provided by @Mike Gieg from Unity in the "Merry Fragmas" Tutorial series. See the part where the animator parameters are set in the coroutine and onphotonserializeview the information is received, this is the key to solving your problem. Hope it helps. Also I highly recommend seeing part three of the merry fragmas series or was it part two well not sure, anyways you should see the whole thing its simple awesome.

This script is using Photon Unity Network, but if you using something else then your code will have to be modified accordingly, all the best.

[code] using UnityEngine; using System.Collections;

public class PlayerNetworkMover : Photon.MonoBehaviour { public delegate void Respawn(float time); public event Respawn RespawnMe; public delegate void SendMessage(string MessageOverlay); public event SendMessage SendNetworkMessage;

 Vector3 position;
 Quaternion rotation;
 float smoothing = 10f;
 float health = 100f;
 bool aim = false;
 bool sprint = false;
 bool initialLoad = true;

 Animator anim;

 void Start()
 {
     anim = GetComponentInChildren<Animator> ();
     if(photonView.isMine)
     {
         transform.Find ("Head Joint/First Person Camera/GunCamera/Candy-Cane").gameObject.layer = 11;
         transform.Find ("Head Joint/First Person Camera/GunCamera/Candy-Cane/Sights").gameObject.layer = 11;
         
         GetComponent<Rigidbody> ().useGravity = true;
         
         GetComponent<FirstPersonCharacter> ().enabled = true;
         GetComponent<FirstPersonHeadBob> ().enabled = true;
         GetComponent<SimpleMouseRotator> ().enabled = true;
         GetComponentInChildren<PlayerShooting> ().enabled = true;
         GetComponentInChildren<AudioListener> ().enabled = true;
         
         foreach(SimpleMouseRotator rot in GetComponentsInChildren<SimpleMouseRotator> ())
             rot.enabled = true;
         
         foreach(Camera cam in GetComponentsInChildren<Camera>())
             cam.enabled = true;
     }
     else
     {
         StartCoroutine("UpdateData");
     }
 }

 IEnumerator UpdateData () 
 {
     if(initialLoad)
     {
         initialLoad = false;
         transform.position = position;
         transform.rotation = rotation;
     }

     while(true)
     {
         transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * smoothing);
         transform.rotation = Quaternion.Lerp(transform.rotation, rotation, Time.deltaTime * smoothing);
         anim.SetBool("Aim", aim);
         anim.SetBool ("Sprint", sprint);
         yield return null;
     }
 }

 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.SendNext(transform.position);
         stream.SendNext(transform.rotation);
         stream.SendNext(health);
         stream.SendNext(anim.GetBool ("Aim"));
         stream.SendNext(anim.GetBool ("Sprint"));
     }
     else
     {
         position = (Vector3)stream.ReceiveNext();
         rotation = (Quaternion)stream.ReceiveNext();
         health = (float)stream.ReceiveNext();
         aim = (bool)stream.ReceiveNext();
         sprint = (bool)stream.ReceiveNext();
     }
 }

 [RPC]
 public void GetShot(float damage, string enemyName)
 {
     health -= damage;

     if (health <= 0 && photonView.isMine){

         if(SendNetworkMessage != null)
             SendNetworkMessage(PhotonNetwork.player.name + " was killed by " + enemyName);

         if(RespawnMe != null)
             RespawnMe(3f);

         PhotonNetwork.Destroy (gameObject);
     }
 }

}1

[/code]

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Sync animaor of child prefab 0 Answers

Network - Sync Issue 0 Answers

Network Animation Problem 1 Answer

Multiple Cars not working 1 Answer

Network animations 2 Answers


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