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

0 favourites
  • 8 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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!

  • 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!

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

    For each Worker
    Tree.Occupied = False
    Pick nearest Tree to worker
    ----> <If Tree found> 
    ----> Tree.Occupied = True 
    ----> Worker.Go to tree
    [/code:3b0gfoir]
  • 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?

  • 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

  • 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"

  • It's implicit, if "Pick nearest" return something, it's <Found>.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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:

    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 
    [/code:305s3aic]
  • Got it working! Thanks nimos!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)