Search Unity

AI Help

Discussion in 'Navigation' started by dcnsll, Mar 2, 2022.

?

AI System

  1. AI

    0 vote(s)
    0.0%
  2. AI

    0 vote(s)
    0.0%
  1. dcnsll

    dcnsll

    Joined:
    Nov 4, 2019
    Posts:
    1
    Guys, I want to make a pizza restaurant. Customers will come and sit I will give them pizza. I want to make the same quantity customer with the same table quantity. How Can I check like the table has already been taken then set the destination to another also I want to add expansion to the restaurant? How can I handle these AI s? I want something like Fashion Universe in Playstore. Thanks

    reddiir.PNG
     
  2. r31o

    r31o

    Joined:
    Jul 29, 2021
    Posts:
    460
    To handle if a table has been taken you could have two arrays: One the destination points for the tables (destination point for table1, for table2…) and another one of booleans to check if the table has been taken. When a customer sits on a table the boolean of the array that corresponds to that table is set to true, and when he leaves is set to false.
    The AI will loop through all the boolenas untill it finds one that is true and then go to the position of the corresponding table.
    Some code:
    Code (CSharp):
    1. public NavMeshAgent agent;
    2.  
    3. public bool[] areTablesTaken;
    4. public Vector3[] tablesPositions;
    5.  
    6. //Call it when you need to the agent to go to a table
    7. void GivePizza()
    8. {
    9.     for(int i = 0; i < areTablesTaken; i++) //Loop for all the tables
    10.     {
    11.         if(areTablesTaken[i]) //Is the table taken?
    12.         {
    13.             agent.SetDestination(tablesPosition[i]); //Go to the table
    14.             return; //We have a table, no need of checking the others
    15.         }
    16.     }
    17. }
    18.  
    19. //Call this to change the tables state
    20. public void ChangeTableState(int id)
    21. {
    22.     areTablesTaken[i] = !areTablesTaken[i]; //If it was taken we set to not taken and vice versa
    23. }
    24.        
    The code needs to be adjusted, but that is the basic idea.
    Also, I wrote this on the fly, maby it has errors.