Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Behavior for long range enemy when player is too close

Discussion in 'AI & Navigation Previews' started by juicedup, Oct 29, 2022.

  1. juicedup

    juicedup

    Joined:
    Aug 18, 2019
    Posts:
    47
    EDIT: sorry I posted in the wrong forum, I followed a google link and it took me to previews forum instead of the main forum, i reposted the thread here: https://forum.unity.com/threads/behavior-for-long-range-enemy-when-player-is-too-close.1354871/
    feel free to delete this thread, mods
    1. I'm working on the AI system for an action game. My question is about pathfinding. I have a long range pathfinding a position a bit far from the player say I want it to be 5 units away for it to stop pathfinding and do an attack. What should I do if the player gets too close? how can I tell the enemy where to go if it's TOO CLOSE
    2. keep in mind the levels are randomly generated so I can't make predetermined spots for it to go should I just make it raycast in a direction away from the player and go to the hit point if there's nothing in the way?what if the enemy is a corner?
    3. should I make it so the enemy has a short range attack and have the enemy attack until it dies?
    4. how do games typically approach this problem?
     
    Last edited: Oct 29, 2022
  2. MaxWitsch

    MaxWitsch

    Joined:
    Jul 6, 2015
    Posts:
    114
    Do you use a simplification layer for your AI? For example a FiniteStateMachine or a BehaviorTree?
    These systems allow you to conditionally change behavior.
    I found myself in the same situation and decided to setup my AI with a BehaviorTree.
    I chose a BT because it has an easy to understand decision path.

    To elaborate BehaviourTrees a little more...
    after the AI makes a choice (e.g. "close for ranged weapon")
    You can just go to a new branch to make new decisions ("should the AI run away/should the AI go to CloseCombat").

    Finite State Machines (as known from Animator) could also be a solution.
    However, sloppy FSMs can quickly become very confusing and are a bit more difficult to debug.

    There are some very feature-rich and easy to use assets available on the Assetstore.