How do I - AI workers that wont go to the same object.

Get help using Construct 2

Post » Fri Oct 09, 2015 1:58 pm

Hello!

I recently started playing around with Construct 2 and I have some little experimental thing going where I have AI Pathfinding units that chop down trees and bring the wood back to store it.

Currently all my units will go to the same tree and the one that gets there first will chop it down, the rest of the units that went to the tree are beaten to the task by the first unit and get confused. How do I make the Pathfinding AI units go to the closest tree that doesn't already have a unit on the way to it? I basically want to have a unit call dibs on a tree/object and then have the other units know that it is taken and go elsewhere.

Thanks for any help you can give! :D
B
3
Posts: 4
Reputation: 183

Post » Fri Oct 09, 2015 2:19 pm

Biskit555 wrote:Hello!

I recently started playing around with Construct 2 and I have some little experimental thing going where I have AI Pathfinding units that chop down trees and bring the wood back to store it.

Currently all my units will go to the same tree and the one that gets there first will chop it down, the rest of the units that went to the tree are beaten to the task by the first unit and get confused. How do I make the Pathfinding AI units go to the closest tree that doesn't already have a unit on the way to it? I basically want to have a unit call dibs on a tree/object and then have the other units know that it is taken and go elsewhere.

Thanks for any help you can give! :D

You almost answered you own question :D A way to do it is to mark the tree as "occupied" the moment a worker "select" it.

Code: Select all
For each Worker
Tree.Occupied = False
Pick nearest Tree to worker
----> <If Tree found>
----> Tree.Occupied = True
----> Worker.Go to tree
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri Oct 09, 2015 2:55 pm

Aha! I thought it would be something like this, thanks. One thing - I can't seem to find the "Pick nearest " action in the Pick section. Am I missing something?
B
3
Posts: 4
Reputation: 183

Post » Fri Oct 09, 2015 3:12 pm

Biskit555 wrote:Aha! I thought it would be something like this, thanks. One thing - I can't seem to find the "Pick nearest " action in the Pick section. Am I missing something?

Its an object functionality not a system one, and its actually called "Pick Nearest/Furthest" you can find it under the section Size & Position
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri Oct 09, 2015 3:39 pm

OK bear with me here I got that part - where can I find the "If X found" function? The only similar thing I can find is for pathfinding "On path found" :?
B
3
Posts: 4
Reputation: 183

Post » Fri Oct 09, 2015 3:47 pm

It's implicit, if "Pick nearest" return something, it's <Found>.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Post » Fri Oct 09, 2015 3:52 pm

Biskit555 wrote:OK bear with me here I got that part - where can I find the "If X found" function? The only similar thing I can find is for pathfinding "On path found" :?

Its not really a function, why I put it in <> to just show that if it was the case, then what would happen.

<If tree found> is automatically done if its true.

To explain it, imagine this:
Code: Select all
3 workers
2 Unoccupied tree

For each Worker <---- Will run 3 times in a row since there are 3 workers.
Tree.Occupied = False  <---- Will pick all tree which are not occupied. In this case 2.
Pick Nearest Tree to Worker   <--- C2 will check the distance from each tree to the current Worker and select the nearest one.
<If tree found>   <--- Since it picked a tree it must be true otherwise it of course couldn't pick any and therefore false.

So when the first two workers have been assigned a tree, there will be no one left for the last worker and therefore it wont be true. In which case you can throw in an else.

<If tree found>
----> Go to tree
<Else>
----> Do something else
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,828

Post » Fri Oct 09, 2015 6:35 pm

Got it working! Thanks nimos!
B
3
Posts: 4
Reputation: 183


Return to How do I....?

Who is online

Users browsing this forum: adamebastin, ketramtu18 and 8 guests