Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multi-Behavior Ai

Discussion in '2D' started by jsull1, May 23, 2018.

  1. jsull1

    jsull1

    Joined:
    Apr 3, 2018
    Posts:
    121
    Hello, I’m trying to make a 2D an that follows a path and then chases my character if he is seen. Doing both these behaviors on one script is causing neither of the functions to work correctly. Is this a good point to learn about behavior trees or state machines, or should I just keep at 1 script until it works?
     
  2. Hyblademin

    Hyblademin

    Joined:
    Oct 14, 2013
    Posts:
    725
    I don't understand what you're asking when you refer to using one script. But I can answer your other question: Yes, learn about state machines and behavior trees.

    As you try to make computer-controlled behavior more interesting, both will become useful to you. In this case, you don't really need a fully-fledged implementation of either, just a boolean that flags whether the player has been detected, and two separate behaviors for following a path and for chasing the player. If the flag is true, run the chase player logic, otherwise run the follow path logic.