Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

AI question: CPU going to the player's nearest node

Discussion in 'Scripting' started by Feretro, Nov 2, 2018.

  1. Feretro

    Feretro

    Joined:
    Apr 18, 2017
    Posts:
    57
    Hello! As usual, I am as noob as that I don't even know if I can just ask what I am about to ask! :-O

    I am thinking of a ""3D game"" that is basically a simple map/maze where two characters (Player and CPU) can move from a "node" to another. Now the AI should make CPU seek player through those nodes. In your opinion how do you accomplish this task?

    CPU should use the shortest way to reach last known node the player was (or next node player will be), but as a dumb and a noob, how can I calculate the shortest path from actual cpu node to last (or next) player node?

    Thanks and sorry for my english!
     
  2. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,731
    You might want to start researching A* pathfinding or Unity NavMesh and NavMeshAgents.
     
  3. mvinc006

    mvinc006

    Joined:
    Jan 1, 2018
    Posts:
    91
  4. Feretro

    Feretro

    Joined:
    Apr 18, 2017
    Posts:
    57
    Thanks so much! I will look for A* and NavMesh! :)
     
  5. mvinc006

    mvinc006

    Joined:
    Jan 1, 2018
    Posts:
    91
    If you do go down the route of A*, try to limit the number of ‘for’ or ‘while’ loops you are doing, because as you scale up you’ll get performance problems. That’s what I figured out anyway. Just be as efficient as possible with how you fit it together and you’ll be fine.