Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am making a game where I have a background image of a neighborhood. Each location has a different number of customers that are generated to walk on sidewalks. They all walk to a specific location (like a stand or cart that sells stuff), after they get to location I want them to interact with the cart. However, if another customer is already in a sale interaction then the others get in line in order of arrival. After the transaction the customers walk off screen. Any information on how I can do this and what game engine would be needed? Any one have any idea where I should go for this. I already have my game done up through Eclipse/Java without any game engine.

share|improve this question
Do they stick to the sidewalk always, or do they leave the sidewalk to get in line? Are there obstacles? – tyjkenn Mar 27 '12 at 23:04
they would leave the side walk to walk across the street or to get in line. there are no obstacles. Basically, the "day" starts and customers start showing up from either 2 or 3 spawn locations and walk towards the cart, if price is too high they just walk away, if someone is already being "served then they wait in line (go to end of line if others are in line already) – Robert H. Mar 27 '12 at 23:16
Pretty broad, pretty too broad. – Byte56 Mar 27 '12 at 23:36
"I already have my game done..." so what do you need from us? – yoozer8 Mar 28 '12 at 3:21
What I meant by already have the game done up through eclipse is that I have gotten to this point and have done everything without using a game engine so I am not sure it adding a game engine in just to do this would matter. – Robert H. Mar 28 '12 at 15:55

What you are looking for is a Queue, check the destination, and if there is already somebody there, add the person to the queue, and then query the queue to figure out where to stand (you can use vectors to figure out where exactly to stand in the line)

Best I could give you is C++ code, so see if this works...

function addPerson(int x, int y, Location placeToGo)
    new Person(x,y,placeToGo);

Person::Person(int newx, int newy, Location placeToGo)
    x = newx;
    y = newy;
    wantToGoTo = placeToGo;
    PathFind myPath = NULL;
    if(placeToGo.queue.isEmpty() == false)
        Person inFrontOfMe = placeToGo.queue.queryEnd();
        myPath = new PathFind(inFrontOfMe.location);
        myPath = new PathFind(placeToGo);

If anybody knows what to do better, please feel free to edit this!

share|improve this answer

Use the number of customers in line to offset the destination. For example, say the line is below the stand at (200,200), customers are spaces 25 pixels, and there are three customers in line. The back of the line will be at (200,200+(3*25)), or (200,275).

Use the distance formula to check and see if the customer is in range.

xdist = backOfLine.x-cust.x;
ydist = backOfLine.y-cust.y;
dist = Math.sqrt(xdist*xdist+ydist*ydist);

If the distance is small enough, then the customer is in range to "see" the booth. To actually move the customer, find the unit components of the distance, and then multiply by your desired speed.

uxdist = xdist/dist; //these are our unit components
uydist = ydist/dist; //with a hypotenuse of 1
uxdist *= speed;
uydist *= speed;

Then just move by uxdist and uydist each frame. This will get them to the line. Once distance is around zero, he reached the line and gets assigned a queue number and stops. When a customer in front is served, he moves up in the queue, walks to the spot designated for that queue, and stops. Let's say for example, he is third in line. A signal is sent that the line is moving, and so he moves up as second in line. His destination becomes booth.y+(25*queueLocation). He walks until he reaches that destination, and then stops, and the system resets. It repeats this process until the signal is sent while the customer is first in line. This means he is done. He picks a random direction, and walks off.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.