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 JJNCreator · Jan 01, 2015 at 02:51 PM · animationphotonupdates

Photon animation issue

Hi, I'm working on a multiplayer FPS and I'm using Photon+ for the networking. I have two scripts: one that does movement, and one that sends that movement to other clients. However, the movement is working fine, but the animations aren't. By the way, I'm using legacy animations, not animator.

Here's the one for movement

 using UnityEngine;
 using System.Collections;
 
 public enum AniState
 {
     Idle,
     Walking,
     Jumping,
     Firing
 }
 public class Movement : MonoBehaviour {
  
 
     public float defaultSpeed = 10.0f;
     public float jumpSpeed = 20.0f;
     private Vector3 direction = Vector3.zero;
     private CharacterController controller;
     private Animation ani;
     private float verticalVelocity = 0;
     public AniState state;
 
     // Use this for initialization
     void Start () {
         controller = GetComponent<CharacterController>();
         ani = GetComponent<Animation>();
 
      //   ani.wrapMode = WrapMode.Loop;
     
     }
     
     // Update is called once per frame
     void Update () {
         direction = transform.rotation * new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
 
        // CurrentAnimation();
 
         if (direction.magnitude > 0.5f)
         {
             direction = direction.normalized;
             state = AniState.Walking;
         }
         else
         {
             state = AniState.Idle;
         }
 
 
       /*  if (Input.GetButton("Vertical")) {
             ani.CrossFade("soldierWalk");   
             controller.SimpleMove(direction * defaultSpeed);
         }
               
         else {
             ani.CrossFade("soldierIdle");
 
         }*/
         if (controller.isGrounded)
         {
             verticalVelocity = 0;
         }
         else
         {
             state = AniState.Jumping;
         }
 
         if (controller.isGrounded && Input.GetButtonDown("Jump"))
         {
             verticalVelocity = jumpSpeed;
         }
         CurrentAnimation();
     
     }
     void FixedUpdate()
     {
         Vector3 dist = direction * defaultSpeed * Time.deltaTime;
 
         if (controller.isGrounded && verticalVelocity < 0)
         {
             state = AniState.Idle;
 
             verticalVelocity = Physics.gravity.y * Time.deltaTime;
 
         }
         else
         {
             if (Mathf.Abs(verticalVelocity) > jumpSpeed * 0.50f)
             {
                 state = AniState.Jumping;
             }
             verticalVelocity += Physics.gravity.y * Time.deltaTime;
 
         }
        
         dist.y = verticalVelocity * Time.deltaTime;
 
         controller.Move(dist);
      //   ani.CrossFade("soldierWalk");
     }
     public void CurrentAnimation()
     {
         switch (state)
         {
             case AniState.Idle:
                 Idle();
                 break;
             case AniState.Walking:
                 Walk();
                 break;
             case AniState.Firing:
                 Fire();
                 break;
             case AniState.Jumping:
                 Jump();
                 break;
         }
     }
     private void Idle()
     {
         if (state == AniState.Idle)
         {
             ani.CrossFade("soldierIdle");
         }
     }
     private void Walk()
     {
         if (state == AniState.Walking)
         {
             ani.CrossFade("soldierWalk");
         }
     }
     private void Fire()
     {
         ani.CrossFade("soldierFiring");
     }
     private void Jump()
     {
         if (state == AniState.Jumping)
         {
             ani.CrossFade("soldierFalling");
         }
     }
 }


And here's the one for network movement:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkMovement : Photon.MonoBehaviour {
     private Vector3 realPos = Vector3.zero;
     private Quaternion realRot = Quaternion.identity;
     private Animation ani;
     private bool gotFirstUpdate = false;
     private AniState state;
 
     // Use this for initialization
     void Start () {
    //     ani = GetComponent<Animation>();
 
     
     }
     
     // Update is called once per frame
     void Update () {
         if (photonView.isMine)
         {
 
         }
         else
         {
             transform.position = Vector3.Lerp(transform.position, realPos, 0.1f);
             transform.rotation = Quaternion.Lerp(transform.rotation, realRot, 0.1f);
         }
     
     }
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if (stream.isWriting)
         {
          //   stream.SendNext((int)state);
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
             Movement move = GetComponent<Movement>();
             stream.SendNext((int)move.state);
          
 
         }
         else
         {
         //    state = (Movement.AniState)(int)stream.ReceiveNext();
             realPos = (Vector3)stream.ReceiveNext();
             realRot = (Quaternion)stream.ReceiveNext();
             Movement move = GetComponent<Movement>();
             move.state = (AniState)stream.ReceiveNext();
 
 
             if (gotFirstUpdate == false)
             {
                 transform.position = realPos;
                 transform.rotation = realRot;
                 gotFirstUpdate = true;
             }
         }
     }
 }
 

If anyone knows a solution, please tell me. I know I'm not the first guy to ask this question, but I have been working on this for a few days. Any help would be much appreciated!

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

0 Replies

· Add your reply
  • Sort: 

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

25 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Photon Syncing Animations 2 Answers

Animation via Photon Networking without Animator 0 Answers

Enable logging in custom script (Photon Server) 2 Answers

Photon Instantiate doesn't always work 0 Answers

Photon Play Animation 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