Search Unity

Bots with Unet HLAPI?

Discussion in 'UNet' started by robochase, Sep 6, 2017.

  1. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    I've been contemplating adding bots to my game, but I'm wondering the best way to go about it.

    I know I've seen some stuff in the HLAPI for like multiple 'players' on a single machine (generally for splitscreen stuff), but maybe this should also be used for bots? Bots in my game will be compositionally identical to players in every way except an AI on the host's machine would control them.

    I know this post is pretty open-ended, but any pointers in this realm would be helpful. Thanks!
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Two ways we choose between:
    1. Build a custom bot with its logic
    2. Simulate actions for player.
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    An easy way to get started would be to just build the bot like you would for a single player game, but just wrap all the bot logic in a check for "hasAuthority" and disable any player inputs.

    I like to include an AI script on the prefab, and activate it if it is AI controlled, and have that script access the same functions that my player input button and key presses use. I don't know if that is an ideal way of doing it though.
     
  4. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Implement the AI in a NetworkBehaviour and sync all the relevant action to the clients via SyncVars/NetworkTransform.
    There are a lot of ways to implement AI if that's what you are asking. Look into BehaviourTrees, (Finite)State Machines, etc.