Select units and move

Hi, I’m building a grand strategy game, how do I do selecting a unit then move it to the cursor the next click. If I click on another unit, it moves the first unit there instead of deselecting the unit. Also when I have two of the same sprite on screen, when I select one of them, both of them moves. Please help thanks :frowning:

I love the pathfinder. I haven’t used it lately so I was a bit rusty. When you click on an object and set the scene selected to true, you can also set an object variable like selected to True. That way you can pick it again by looking for object(s) with their selected Boolean set to true. You then need to set everything back to false.

If the destination is unreachable, it adds an X to the location. That’s just a way to demonstrate the pathfinder behavior for you and anyone else who reads this. The objects on the left have the pathfinder behavior and the rocks have the pathfinder obstacle behavior. The changed Boolean prevents the object from moving with the same mouse click.

Try online: Click an object on the left and then a 2nd click for the destination.

Shortcomings: To keep it simple, objects can move to occupied locations. If you click overlapping objects all objects get selected and will move together.

1 Like

Thanks so much for the reply :slight_smile:

1 Like