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 Rabbit · Jul 06, 2013 at 08:02 PM · animationmultiplayerphoton

Photon Cannot sync animations

Hello guys and thanks for your time. this is my first post but I have been reading this forum for ages and learnt a lot.

My problem is I cannot workout why the animation state arent getting shown to other clients.

I cannot for the life of me work out how to setup void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)

using my controller it never works. I am a average at best programmer and have been fighting with this for days.

Here is my controller script, both scripts are attached to player prefab.

using UnityEngine; using System.Collections;

public class PlayerControl : Photon.MonoBehaviour {

 enum CharacterState  {  
     Idle,  
     WalkingForward,  
     WalkingBackward,
     Running,  
     Limping
 }; 
 
 public CharacterState _characterState;
 private Transform _myTransform;                //our cached transform
 private CharacterController _controller;    //our cached CharacterController
 private Vector3 _moveDirection;                //This is the direction our character is moving    
 
 
 public float walkSpeed = 1f;
 public float runSpeed = 2f;
 public float limpSpeed = 0.3f;
 public bool _running = false;
 public bool _limping = false;
 public float gravity = 20f;
 
 
 //Called before the script starts
 public void Awake() {
     _myTransform = transform;                                //cache our transform
     _controller = GetComponent<CharacterController>();        //cache our charactercontroller
     
     
     if (!photonView.isMine) {
          GetComponentInChildren<Camera>().enabled = false; // disable the camera of the non-owned Player; 
          GetComponentInChildren<AudioListener>().enabled = false; // Disables AudioListener of non-owned Player - prevents multiple AudioListeners from being present in scene.
      }
     
     
     _characterState = CharacterState.Idle;
 }

 
 // Use this for initialization
 void Start () {
     _moveDirection = Vector3.zero;                            //zero our the vector3 we will use for moving our player
 }
 
 // Update is called once per frame
 void Update () {
     if(networkView.isMine) {
         if(Input.GetKeyUp(KeyCode.R))
             ToggleRun();
             
         if(Input.GetKey(KeyCode.W)) {    
             if(!_running) {
                 if(!_limping) {
                      WalkForward();
                 } else {
                     LimpingForward();    
                 }
             }
                 
             if(_running && !_limping) 
                 RunForward();
             
             if(_limping)
                 LimpingForward();
         } else {
             
             _characterState = CharacterState.Idle;    
         }    
         CurrentAnimation();        
     }
 }
 
 public void ToggleRun() {
     _running = !_running;
 }
 
 public void ToggleLimp() {
     _limping = !_limping;    
 }
 
 void WalkForward() {
     // is the controller on the ground?
     if (_controller.isGrounded) {
         //Feed moveDirection with input.
            _moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
            _moveDirection = transform.TransformDirection(_moveDirection);
         //Multiply it by speed.
            _moveDirection *= walkSpeed;
         _characterState = CharacterState.WalkingForward;
     }
     //Applying gravity to the controller
        _moveDirection.y -= gravity * Time.deltaTime;
     //Making the character move
     _controller.Move(_moveDirection * Time.deltaTime);        
 }
 
 void RunForward() {
     // is the controller on the ground?
     if (_controller.isGrounded) {
         //Feed moveDirection with input.
            _moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
            _moveDirection = transform.TransformDirection(_moveDirection);
         //Multiply it by speed.
            _moveDirection *= runSpeed;
         _characterState = CharacterState.Running;
     }
     //Applying gravity to the controller
        _moveDirection.y -= gravity * Time.deltaTime;
     //Making the character move
     _controller.Move(_moveDirection * Time.deltaTime);        
 }
 
 void LimpingForward() {
     // is the controller on the ground?
     if (_controller.isGrounded) {
         //Feed moveDirection with input.
            _moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
            _moveDirection = transform.TransformDirection(_moveDirection);
         //Multiply it by speed.
            _moveDirection *= limpSpeed;
         _characterState = CharacterState.Limping;
     }
     //Applying gravity to the controller
        _moveDirection.y -= gravity * Time.deltaTime;
     //Making the character move
     _controller.Move(_moveDirection * Time.deltaTime);        
 }
 
 public void CurrentAnimation() {    
     switch(_characterState) {
         case CharacterState.Idle:
             IdleAnim();
             break;
         case CharacterState.WalkingForward:
             WalkingForwardAnim();
             break;
         case CharacterState.WalkingBackward:
             WalkingBackwardAnim();
             break;
         case CharacterState.Running:
             RunningAnim();
             break;
         case CharacterState.Limping:
             LimpingAnim();
             break;
     }
             
 }
 
 
 public void IdleAnim() {
     animation.CrossFade("Idle");
 }
 
 public void WalkingForwardAnim() {
     animation["Walk"].speed = 1f;
     animation.CrossFade("Walk");    
 }
 
 public void WalkingBackwardAnim() {
     animation["Walk"].speed = -1f;
     animation.CrossFade("Walk");    
 }
 
 public void RunningAnim() {
     animation.CrossFade("Run");        
 }
 
 public void LimpingAnim() {
     animation.CrossFade("injury on right leg and arm");    
 }
 

}

and this is my network script

 using UnityEngine;
 
 public class NetworkCharacter : Photon.MonoBehaviour
 {
     private Vector3 correctPlayerPos = Vector3.zero; // We lerp towards this
     private Quaternion correctPlayerRot = Quaternion.identity; // We lerp towards this
     // Update is called once per frame
     void Update()
     {
         if (!photonView.isMine)
         {
             transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
             transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
         }
     }
     
     
     void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
        if (stream.isWriting)
        {
            //We own this player: send the others our data
            stream.SendNext((int)PlayerControl.CharacterState);
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
        }
        else
        {
            //Network player, receive data
            PlayerControl.CharacterState = (PlayerControl.CharacterState)(int)stream.ReceiveNext();
            correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();
        }
     }
     
 }
Comment
Add comment · Show 2
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 Rabbit · Jul 07, 2013 at 02:49 PM 0
Share

Can no one see the problem? :(

avatar image KuPAfoo · Dec 01, 2013 at 08:48 PM 0
Share

Your serialize view is identical to $$anonymous$$e, and I send animations just fine. Where my problem lies (how I found this thread) is how to send render states to specific prefabs.

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by Pixelblock Games · Jul 17, 2013 at 12:10 AM

You have to make a script that syncs the animations through the network, I don't know C# so I can't help you :(

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
-1

Answer by kidne · Feb 12, 2015 at 09:16 PM

I had your exact same issue. What I had to do was just create my own locomotion script, because TPC is just terrible.

Comment
Add comment · Show 2 · 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 tobiass · Feb 13, 2015 at 01:50 PM 0
Share

And TPC is?

avatar image kidne · Feb 17, 2015 at 09:12 AM 0
Share

third person controller!

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make game object animation without animator visible to all players in photon pun? 2 Answers

Photon animation syncing 0 Answers

How can I play Animations on a Photon-Network ? 0 Answers

Unity Photon: animation syncing 1 Answer

How do you sync animations in Photon (free version)?,How do you sync animations in Photon(free version)? 0 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