AI in different position for different players

Options
Hi guys,
I have two players connecting to a map that has one enemy on it. When player one connects, he sees the enemy in one position, however when player 2 connects, he sees the enemy in a different position. I have a Photon View attached to the enemy, and its observing the script that controls the enemys movement, and I dont know what Im doing wrong.

This is on the enemy.
using UnityEngine;
using System.Collections;

public class RaptorScript : Photon.MonoBehaviour {
	private Animator anim;
	private GameObject player;
	private GameObject player2;
	private float distance;
	private NavMeshAgent agent;
	private Vector3 position;
	private Quaternion rotation;
	private bool isAlive = true;
	float lerpSmoothing = 5f;

	// Use this for initialization
	void Start () {
		anim = GetComponent<Animator>();
		player = GameObject.FindGameObjectWithTag("Player");
		agent = GetComponent<NavMeshAgent>();
	
	}
	
	// Update is called once per frame
	void Update () {

		if(player == null)
		{
			player = GameObject.FindGameObjectWithTag("Player");
		}
		distance = Vector3.Distance(transform.position, player.transform.position);

		anim.SetFloat("distanceToPlayer", distance);

		agent.SetDestination(player.transform.position);

	}
	

	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if(stream.isWriting)
		{
			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
		}
		else {
			position = (Vector3)stream.ReceiveNext();
			rotation = (Quaternion)stream.ReceiveNext();
		}
	}


}

Comments

  • vadim
    Options
    Hi,
    How do you instantiate enemies?
    Log OnPhotonSerializeView calls and all other code where position changed. This should help find out what's going on.
  • Hi Vadim,
    For the enemy, I am not instantiating it over the network. It is just on the map already. I have a photon view on the enemy, and I also have a script that controls the enemy movement. The photon view observes this script.

    It seems to be working okay, but I also saw that there is a component called a "Photon Transform View " that can be added to a Gameobject. Should this be used instead?
  • vadim
    Options
    If everything is already working, you need good reasons to use From Photon Transform View helper.
    Accordingly to the description, it may help save bandwidth or make synchronized values appear smoother.
    If you need this then try it.