How do I handle multiple pathfinding objects?

0 favourites
  • 3 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hey

    So I'm about done with this I think. I keep rewriting this little program and getting stuck around the same spot.

    So I want to be able to control multiple units one at a time. If I click a unit they become active, if I click somewhere on the map that is free (using an array to track objects in level) then a little icon will pop up with a couple of options for the units. So far I just want to be able to move to that spot.

    So far, this is working really nicely with one unit, but as soon as I introduce a second, I get problems. For a start, if I move the first unit, the second won't move when ordered to, and will only move after the first unit is selected to move somewhere again. Then, if I move the original unit a second time, the first unit zooms off to the top left corner of the page.

    I figured there's a problem in the logic somewhere, but it's doing my head in trying to work out why this is happening. I'm telling units only to move if a 'isSelected' boolean is true, but as far as I can tell, the units are ignoring this

    I tried creating a global variable that keeps a track of the UID of only the current unit, but even this doesn't seem to work.

    Anyway, some fresh eyes on this would be appreciated, I'm probably missing something very basic.

    Cheers

    https://imgur.com/9H5R3S2

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think when you click a unit, event #5 sets isSelected to true, but event #6 immediately resets it to false.

    Also, you are moving the unit with MoveTo behavior, but checking if it's arrived using Pathfinding behavior event. Does it really work??

    It's pretty hard to figure out what's going on by the screenshot, could you post your capx?

  • Event 6 is testing if, while one unit is selected, another is clicked. Essentially changing the selected unit so that the new one is active.

    Also, you are moving the unit with MoveTo behavior, but checking if it's arrived using Pathfinding behavior event. Does it really work??

    This was it, thankyou! All I had to do was swap the pathfinding check with the moveTo... doh!

    Cheers

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