Playing offline with bot(s)

Hello,

I am working on a game and using the new networking system. Currently, I’m only focusing on having the game work with real players over a network (i.e multiple instances running that communicate with each other). However, later on I plan to implement playing with offline “bot” players. Is that something I should be worried about early in the project? Or is that an easy task at any time?

In my mind, the ideal way of implementing AI “bots” is having the server create and “connect” Player objects (the ones that are able to run Commands), just as if they were real players. BUT, instead of having a real person control them from a separate instance, they would be controlled by the server, again, without the need of extra instances of the application running. If that is possible, then I would not need to worry now, at all. But the question is, that possible to do in Unity with the new net system?

Any help is much appreciated :slight_smile:

I’ve used that system with the old Unity networking without issues, can’t see any reason it wouldn’t work with the new networking system.

Thanks for the reply! So how can I add a bot player to the server in code? I just need a simple example to get started.

An example would be an abstract class Unit that would have most of the general stuff. Then you’d have two classes: Player and Bot and both would inherit from Unit. Most of the stuff such as movement, etc would be in Unit. Bots would have AI behavior, while Player would behave based on human user’s input.

To some extent, you can make the bots just game objects that run on the host of the same type of prefab as real players. In this scenario, the functionality shared by bots and players can be “wrapped” by commands so that remote players can access them.

// used by local bots on host
public void Attack(Vector3 pos)
{
    //do attack
}

//used by real players (local and remote)
[Command]
void CmdAttack(Vector3 pos)
{
    // player specific validation
    Attack(pos)
}