Search Unity

AI for turn-based combat

Discussion in 'Navigation' started by Slabada, Feb 14, 2022.

  1. Slabada

    Slabada

    Joined:
    May 2, 2021
    Posts:
    50
    Hello, I'm making a game where there is a turn-based battle.
    Please tell me how you can implement a simple AI so that the enemy moves through the cells of the player's side and bypasses obstacles. Unfortunately, I don't even have any ideas how to implement such an AI, what to start from, maybe there are some articles? I will be glad of any information that will direct me in the right direction :)

    P.S I apologize in advance if I asked the question in the wrong place.
     
  2. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    If you want to make a AI that chases the player you can do the following:
    -Create a object, you can use a 3d model or some primitive mesh like a capsule.
    -Add a NavMeshAgent to it, and change the radious height and base offset to fit your model.
    -Increase the stoping distance to something like 2-3 so the agent will not try to get inside your player.
    -Open the navigation window and in the bake tab adjust the size of your agent and press bake. All the map MUST be set to static in order to work. If you done correctly you should see some blue things on the walkable part.
    -Add a script the gameobject you created before and open it.
    -In the top side add using UnityEngine.AI;.
    -Add a reference to the navMeshAgent and the player tranform.
    -In Update() add the following:
    agent.SetDestination(player.position)
    agent is the navmesh agent and player the transform you referenced before.
    -Assing the references and play. If you have done correctly the agent will chase you constantly, but keeping a distance of the value you have assigned in the stoping distance of the navmesh agent.
     
    Slabada likes this.