- Home /
How can I make the AI in my game wait in lines?
Hello I am making a 2.5D isometric restaurant management game where the player controls the inner working of their own restaurant. What I am having trouble doing and finding information about is making the customers of my game wait in lines and stop behind each other when there is already somebody occupying the way point or space in front of them.
Because it is supposed to be a restaurant the AI needs to wait in line just like in real life.
I'm not sure if it will help but here is a copy of my script that allows the customers to seek out way points and act in a semi-believable way. I use a nav mesh for the detection of objects.
var waypoints : Transform[]; var waypoint : Transform; var currentWaypoint : int; var agent : NavMeshAgent;
function Awake(){ agent = gameObject.GetComponent.(); agent.speed = Random.Range(2.5, 5); }
function Update () { waypoint = waypoints[currentWaypoint]; agent.SetDestination(waypoint.position); }
function OnTriggerExit(other : Collider){ if (other.name == "0 Start"){ currentWaypoint = Random.Range(1, 3); } }
function OnTriggerEnter (other : Collider) { EatMeal(); if (other.name == "0 Start" || other.name == "3"){ currentWaypoint++; } if (other.name == "1"){ WaitForSoda(); Debug.Log("Is Waiting"); } if (other.name == "2"){ WaitForFood(); Debug.Log("Is Waiting"); } if (other.name == "4 End"){ Destroy(gameObject); } }
function WaitForSoda(){ yield WaitForSeconds(2); currentWaypoint++; }
function WaitForFood(){ yield WaitForSeconds(5); currentWaypoint = Random.Range(5, 12); }
function EatMeal(){ if (currentWaypoint >= 4 && currentWaypoint <= 12){ yield WaitForSeconds(Random.Range(5, 12)); currentWaypoint = 3; } }
For some reason, code does not format correctly after lists. So putting any kind of non-list paragraph after the list fixes the problem.
hm, well i guess it fixed itself or a moderator helped me :P
Which part specifically of your script is not working?
Answer by theMonster · Feb 19, 2014 at 03:45 AM
The easiest thing then is to make a "Threshold" script. The Threshold script will have a function called "isThreshHoldMet", "registerForThreshold", "unregisterForThreshold". Let me know if you have any questions on actual implementation, but it should be pretty straight forward.
Hm that is an interesting solution however I can't seem to find documentation on the implementation, therefore you will have to clarify what the variables registerForThreshold and unregisterForThreshold will do. Thanks :)