[PUN] Multiplayer AI Handling

Hello guys, I want to ask a question.

I have a multiplayer game consisting of four players navigating their way out of a large maze. The players will encounter different monsters on the whole area. So far, the player movement, HP, and shooting (friendly fire) system works perfectly. Now I want to add some monsters in the game. My question is, where should I put the control (or the ‘brain’) of the AI? Because I use PUN cloud, so the player who created the game room can leave without crashing the other players’ game. But what if, that player quit the game, the AI might stop working. Are there other techniques to make the AI system work, such as passing the AI control to the other players?

thanks :slight_smile:

What I like to do is first worry only about the basic AI and THEN the networking. When done with the actuall AI you want to have its brain in the Master Client. Doing so allows for any new Master Clients to seamlessly take over control as long as you instantiated the mob with PhotonNetwork.InstantiateSceneObject or the mob was already placed in the scene using the unity editor.

For this method, the mob on any player’s screen besides that of the MasterClient’s is completely dumb and unaware of the world around it. The only functions that it would perform are Lerping to RPC’d positions,rotation, performing animations, and spawning different dummy projectiles, etc.

A simple script below moves an object around on all player screens using the above method:

Vector3 networkPos;
PhotonView p;
Void Start(){
p = GetComponent<PhotonView>();
}
Void Update)(){
If (PhotonNetwork.isMasterclient){
transform.position += Vector3.up * Time.deltaTime;
p.RPC("updatePos", PhotonTargets.Others, tranform.position);
}else{
transform.position = Vector3.Lerp(transform.position, networkPos, .1f);
}
}
[RPC]
Void updatePos(Vector3 v){
networkPos = v;
}