[Photon Unity Network] Where should I start with AI creation.


I am doing a 2D multiplayer game and I wanna have enemies to fight. I have started to develop this but I have not more than started. My question is; what is the best way to do this? I find that the AI position does not sync over the clients. I tried making the PhotonView observe both the transform and I also have a NetworkCharacter script (from the Marco Polo Tutorial - http://doc.exitgames.com/en/pun/current/tutorials/tutorial-marco-polo#_Toc317517599) which I have tried to observe.

//Proximal Pyro

my thought on the subject:

structure your AI with two main components:

BehaviorComponent: this component will do all the behavior logic and send events , enable it only if you are controlling the photonView, it can be your own script or something like BehaviorDesigner for example and just write new action to "call" events

SyncEventComponent: put all your events in here, for example add an RPC "MeleeAttack" that will sync on every clients melee animation using Trigger in mecanim for one time events + sound, then call the RPC from Behavior component and do calcul damage here instead of RPC/

Photon have two components you can use: "PhotonAnimatorView" to sync all your animation parameters, "PhotonTransformView" or "photonRigidBodyView" using these 2 components you do not need to write code to sync your AI position/rotation/mecanim Parametters,

its simple to manage complex AI this way, you can switch your behavior component easily just need to write one line of code to call your action in your SyncEventComponent

few Action example:

[RPC] public void Action_MeleeAttack()
        anim.SetTrigger ("Melee");
   [RPC] public void Action_RangedAttack()
        anim.SetTrigger ("Ranged");

    [RPC]public override void Action_Die ()
        base.Action_Die ();
        anim.SetBool ("Dead", true);
        Timer.In (despawnDelay, Action_Despawn);

  [RPC]  public override void OnReceiveDamage (ViewID damageSource)
        base.OnReceiveDamage (damageSource);
        anim.SetTrigger ("Damaged");
        //if (!IsInCombat)
        //    OnEnterCombat ();
  [RPC] public void Action_Despawn()
        anim.SetBool ("Dead", false);
        MasterSpawner.instance.DespawnObject (gameObject);