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 Timefrog · Jan 19, 2015 at 03:27 PM · animationnetworkphotondiablo

Animation via Photon Networking without Animator

Hello Guys!

I want to make a simple "Diablo" like RPG with a multiplayer part. So far everything is working fine and smooth. But now i ran into a problem i simply can not solve. I don´t want to use the "animator". Believe me i tried, but it was a complette mess. I simply want my animations (i have a bunch) viewed over the network.

Here is my code:

At first the network manager:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkManager : Photon.MonoBehaviour {
 
     // Use this for initialization
     void Start () {
         PhotonNetwork.ConnectUsingSettings ("Alpha 0.1");
     }
 
     void OnGUI() {
         GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString());
     }
 
     void OnJoinedLobby(){
         PhotonNetwork.JoinRandomRoom ();
     }
 
     void OnPhotonRandomJoinFailed() {
         PhotonNetwork.CreateRoom (null);
     }
 
     void OnJoinedRoom() 
     {
         GameObject myPlayer = PhotonNetwork.Instantiate ("Player", Vector3.zero, Quaternion.identity, 0);
 
         Camera.main.GetComponent<SmoothFollow>().target = myPlayer.transform;
 
         ClicktoMove myPlayerScript = myPlayer.GetComponent<ClicktoMove> ();
         myPlayerScript.isPlayer = true;
     }
 
 }

So far so good.

Here comes my NetworkCharacter script:

 using UnityEngine;
 using System.Collections;
 
 public class NetworkCharacter : Photon.MonoBehaviour 
 
 {
 
     private Vector3 correctPlayerPos;
     private Quaternion correctPlayerRot;
 
     void Update()
     {
         if (!photonView.isMine)
         {
             transform.position = Vector3.Lerp(transform.position, correctPlayerPos, Time.deltaTime * 5);
             transform.rotation = Quaternion.Lerp(transform.rotation, correctPlayerRot, Time.deltaTime * 5);
         }
     }
 
     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
     {
         if (stream.isWriting)
         {
             // We own this player: send the others our data
             stream.SendNext(transform.position);
             stream.SendNext(transform.rotation);
         }
         else
         {
             // Network player, receive data
             this.correctPlayerPos = (Vector3)stream.ReceiveNext();
             this.correctPlayerRot = (Quaternion)stream.ReceiveNext();
         }
     }
 
 }

And then comes my ClicktoMove script. I think this one makes the most problem. Cause in every tutorial so far (example: Marco Polo) they are using the FPS script or a script that is not fitting with this play style.

 using UnityEngine;
 using System.Collections;
 
 public class ClicktoMove : MonoBehaviour {
     
     public float geschwindigkeit;
     public CharacterController steuerung;
     private Vector3 position;
     
     public bool isPlayer;
 
     // Use this for initialization
     void Start () 
     {    
         position = transform.position;
     }
 
     // Update is called once per frame
     void Update () 
     {
 
         if (Input.GetMouseButton (0)) 
         {
 
         //Herausfinden wo der Spieler hingeklickt hat
         Position ();
 
         }
 
         //Spieler zur Position bringen
         Bewegen ();
 
     }
 
     void Position()
     {
         //Position herausfinden
         RaycastHit klick;
         Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 
         if(Physics.Raycast(ray, out klick, 1000))
         {
             position = new Vector3(klick.point.x, klick.point.y, klick.point.z);
         }
     }
 
     void Bewegen()
     {
         if (isPlayer) 
     {
                         
         //Spieler bewegt sich
         if (Vector3.Distance (transform.position, position) > 1) 
             {    
                 Quaternion rotation = Quaternion.LookRotation (position - transform.position);
 
                 rotation.x = 0f;
                 rotation.z = 0f;
 
                 transform.rotation = Quaternion.Slerp (transform.rotation, rotation, Time.deltaTime * 10);
                 steuerung.SimpleMove (transform.forward * geschwindigkeit);
                             
                 animation.CrossFade ("run");
             } 
             else 
             {
                 animation.CrossFade ("idle");
             }
         }
     }
 
 }

I am searching for a solution that my "NetworkCharacter" (that is observed by photonview) is checking "hey! he moved so i will give all players in the network his run animation" or something like that.

I am happy for every help! But please no links to the Marco Polo and no links to the Multiplayer FPS in Unity 3d, Part 10: Networking the animations youtube video. I already checked these.

Thank you very much in advance!

Sry for the bad english - i am from Austria. :)

Comment
Add comment · Show 1
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 · Jan 20, 2015 at 03:40 PM 0
Share

You can take a look at the Vikings Demo, too. It synchronizes animations by sending the "state" of the character. To do so, you need to identify what you need to sync (move direction, (bool)jumping, etc) and send it. On the receiving end, you need to apply the inco$$anonymous$$g values accordingly.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Photon View - Player Names/Properties. 1 Answer

Using Photon View To update Text over the network 1 Answer

Send an Animation through photon network 0 Answers

Problem with animation RPC in Photon 1 Answer

Sync animaor of child prefab 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