playMaker

Author Topic: AI - Customers sorting them selves into lines.  (Read 2883 times)

vonpixel

  • Playmaker Newbie
  • *
  • Posts: 14
AI - Customers sorting them selves into lines.
« on: March 25, 2013, 12:50:24 PM »
Im working on a game right now and have come pretty far.

The game is 2D and fairly simple.Im using 2d tool kit and itween to draw and animate most of my stuff. The player is attempting to attract customers to their cart to sell food too. Ive got more or less everything "done"- and now Im going back over my customers and adjusting and tweeking them.

Right now- they sort them selves into 1 of 2 empty objects just for orginzational sake. 1 is for wandering customers and the other for purchase customers. The purchase ones I would love to set up to sort of stand in a line... and im a bit at a loss of how to do this. Right now they will just stack on each other.

This screen shot will give you a basic idea of what the game looks like..



The customers travel to the truck and when they make contact with the trigger zone infront, the purchase system takes over. Given the way I have the characters moving (itween move to)- what would be a good way to get these guys to stand in a line and let me effect that line easily (such as cash everyone out at once quickly)?

Im guessing I need to impliment collisons, but Im hoping there is an easier logical way.

This is what I was thinking, and I would love some insight.
1. Customer gets the "pruchase zone" destination v3 and moves towards it and sorted into the customer line.
2. Customer maybe gets assigned a # (a little unsure the best way to do this... an array?) and offsets its destination by customer line # x 10?
3. Dynamically update that customer # until it hits the purchase zone?

I would like the line to be somewhat dynamic though and this seems like a very rigid way to go about doing it.

Id really appreciate any suggestions.


kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: AI - Customers sorting them selves into lines.
« Reply #1 on: March 25, 2013, 01:08:32 PM »
this can be simpler than it looks. If you have already sorted your people into empties, then just use their position in the hierarchy of the empty as your "list".
What I mean is you can create an FSM on your empty which loops through all the children it has (Get Child Num + Int add) and then for each children it could do something like (Vector3 multiply (( 0,1,0.1) * child index (the same you used to get the child) ) + SetPosition (in local space to what your vector3 put out)).
This way you can just move your empty around to change the start of the line (because of the local space)

Then, each time when one customer is served, he is unparented from the empty and the second person in the line will now have "index" 1, which makes everyone move on one place.

I see I made it look overly complex but I hope you get my point :D Otherwise I can just fix you up an example project.
Best,
Sven

vonpixel

  • Playmaker Newbie
  • *
  • Posts: 14
Re: AI - Customers sorting them selves into lines.
« Reply #2 on: March 25, 2013, 01:29:34 PM »
Ok- that actually makes a lot of sense.

Ill try this out tonight / tomorrow when I get home from my day job and back into my passion job.

What you describe is more or less what I was thinking, but I was unsure the best way to go about doing it. In my head I had something that was much more complicated than that- but would do the same thing more or less. I like what you have suggested. Seems there will be lots of room in there to expand the line dynamics should I want to.

Thanks for clearing up my vague ideas! Cheers!

vonpixel

  • Playmaker Newbie
  • *
  • Posts: 14
Re: AI - Customers sorting them selves into lines.
« Reply #3 on: March 26, 2013, 07:37:05 PM »
Ok- Im trying things out and getting stuck somewhere. When I add a Get Child Count to count the empty, it doesn't update as my customers get added to it. I can make a next frame event, and basically make a loop and int will update then. I feel like if there was an every frame box there, this would make sense. What am I doing wrong here?


Should I intstead maybe have my customer send an event to the customer line fsm to add its self to the list?

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: AI - Customers sorting them selves into lines.
« Reply #4 on: March 28, 2013, 05:30:26 AM »
I don't think I quite understand... Can't you just use the count action right before you'd use the count variable? In the same state I mean? This could be in the FSM of your customers.
Best,
Sven

vonpixel

  • Playmaker Newbie
  • *
  • Posts: 14
Re: AI - Customers sorting them selves into lines.
« Reply #5 on: March 28, 2013, 01:00:35 PM »
Yeah something must be wrong in my set up. I kind of got around it last night- but.. something isn't right. I must be doing something wrong.

On my Customer Line obj I have an 1 FSM that I set up to count the children as they get added to it using Get Child Count. Only as they get added, the int doesnt go up at all. Ill have 5-6-7 customers in the line, but the Get Child Count still reads 0.

If I add another next frame event, and another state with the same Get Child Count on it and feed the two into each other like a loop, the Get Child Count will actually work and count how many children are in the empty.

I noticed you mention using Get Child Num instead of count. Would I not need to get the count first to have an index int to use Get Child Num on?

I understand how it will all work after I can start lifting out the Child Number... but I can;t figure out how to get a child index in the first place. Nothing seems to work properly.

Ive done actions like this before too, only using vertex counts and stuff.

I would post pics of my FSM to make this easier, but I am at my day job currently.