How do I control my units as an additional separate ones?

Get help using Construct 2

Post » Tue Oct 20, 2015 4:25 pm

Hello,

I wanna to make a kind of strategy game, but I stuck at one point because I can't control the units separately.

For example, I have four unit and one of these ones have to go to cut a tree. In my game I can not do the "select one unit and send to the tree" method! I just select the tree and marking as cutting and after one (or more) unit automatically depart in direction of the tree and will cut it. Of course not the cutting the point, only the control over my units.

So, the main problem that all worker units start do it instead of only one. How should I solve this problem? Something about the UID/IID? I don't know...

Each units have a unique IID number. Somehow I should use it, but I don't know how should I give an order/action to only one unit.

Condition:
- If I clicked a tree

Action:
- A unit with IID 4 (or a random units) start to cut the tree meanwhile the others stay calm.

Please help me I really need the solve it's an essential step! Or any tip/idea?

Thank you all!
B
5
S
1
Posts: 37
Reputation: 441

Post » Tue Oct 20, 2015 5:40 pm

You can use "Pick random instance" and be done, but I guess you'd want the unit closest to the tree to go and start cutting?
If so, you can use "For each" loop which will pick every instance one by one and store the distance of each one to the tree in an array. Then choose the one with the lower value and sent it there. Note that depending on the number of instances it could slow down performance.
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

Post » Tue Oct 20, 2015 6:04 pm

you should create "states" like:

IDLE
MOVING_TO_TREE
CUTTING_TREE
RETURNING_WITH_WOOD

Although it will be hard to only click the tree and have the system decide which "unit" to send.. you'd have to create some sort of identifier to isolate that this is the selected unit that is carrying out the last command. Otherwise there will be no way to pick it. And you will not be able to interrupt their behavior like in most RTSs i.e. select unit and issue a new command.
Last edited by jobel on Wed Oct 21, 2015 3:19 am, edited 1 time in total.
B
96
S
31
G
15
Posts: 1,180
Reputation: 16,017

Post » Tue Oct 20, 2015 7:58 pm

Here's a way to do it by picking the nearest unit

dl.dropboxusercontent.com/u/14855413/nearest.capx

As @jobel said though, it might be difficult to implement in game
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

Post » Tue Oct 20, 2015 8:30 pm

@Scap if you do not find your solution send me a PM. I have some templates for common AI types. You can march in formations, and set up complex routes for them to follow.

I have it so they can be as simple or as complex as you need. They can just march from way-point to way-point, or you can add special commands to the way-points, areas, and paths. (Like Rainbow 6).

Well anyway you can use them in a commercial game, or you can just pick them apart and learn from them. Might save you a lot of time. PM me if you are interested.
B
29
S
8
G
4
Posts: 767
Reputation: 5,985

Post » Wed Oct 21, 2015 7:52 am

here is my starting point - not very well documented by hopefully simple enough to follow

https://goo.gl/F0YdZM (r215 plugins req rexs moveto)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Wed Oct 21, 2015 3:45 pm

Thanks guys it's working! I can separately control the units now if I want it. I used the Pick random instances and Nth instance. I don't know the array yet, but i will learn it as well meanwhile I make this game.

Thanks for the exemples, I check this ones and try to learning more :) I'm sure that I will be more "beginner" questions in the future which will connect to this project. I hope you guys will help me next time too. Thanks!
B
5
S
1
Posts: 37
Reputation: 441

Post » Wed Oct 21, 2015 3:52 pm

@jojoe Of course I need these templates! Unfortunately I couldn't send a PM for you because I didn't reach the 500 reputations yet and until I haven't this amount (or more) not possible the PM sending. So, If you can send me one with these templates. Im sure it's going to be very useful for me! Thank you.
B
5
S
1
Posts: 37
Reputation: 441


Return to How do I....?

Who is online

Users browsing this forum: Nicolas951, Shenkai the ssj, Yahoo [Bot] and 26 guests