Forum Discussion

motorsep's avatar
motorsep
Start Partner
5 months ago

Simple enemy AI tutorial needed

Does Meta have any plans to create an enemy AI tutorial using a simple setup (not using those stock Unity Assets) - a cube with an "arrow" (representing direction it's looking at) that idles, until player comes into view cone and then cube starts chasing player ?

7 Replies

    • motorsep's avatar
      motorsep
      Start Partner

      I mean Zombies from Chop'n'Pop template project. For some reason, if I change anything AI related in there, zombies (or nav mesh perhaps) stop working. If I try added Zombie asset into any other world and try making super simple AI with it (just like what I described in my OP) - it doesn't work either. 

  • I might do a tutorial like this after this current competition ends on the 11th, until then I'm pretty swamped. 

    Without getting too far into the nitty gritty, I use States / a State Machine in combination with an update loop for this. 

    The StateMachine is just a plain ole class (not a Component) that calls functions on State classes, which encapsulate specific behaviors (like Idle, Attack, Death, whatever). This keeps your behaviors separate and neatly organized. 

    You can create a basic update loop within a Component by connecting to the hz.World.onUpdate local broadcast event. My implementation usually looks like this:

    this.connectLocalBroadcastEvent(hz.World.onUpdate, (update: { deltaTime: number }) => { this.stateMachine.update(deltaTime)  });

    ---

    I used this setup to create the behaviors seen here. 

    https://www.youtube.com/watch?v=ZnY26YfpL20

    If you want to know more let me know, I'm happy to share some typescript files for a basic state machine setup. 

     

    • motorsep's avatar
      motorsep
      Start Partner

      I might do a tutorial like this after this current competition ends on the 11th, until then I'm pretty swamped.

      I'll be waiting for it :)

      Btw, how did you get custom animated characters into the Horizon Worlds? I thought it was not possible.

      • scarcesoft's avatar
        scarcesoft
        MHCP Partner

        I'm working on a github repo with an example of an AI cube using a state machine. Check out this repository in about half an hour.

        As far as the animated characters go, mine are made using a custom animation system I developed for characters made up of parts. For things like robots, it works just as well as "real" animation. I'll be releasing another tutorial series soon for how to "chop up" whole characters into parts nicely.