- Home /
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. :)
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.
Your answer
Follow this Question
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