Multiple characters collecting one item!?

Get help using Construct 2

Post » Sun Oct 05, 2014 9:25 pm

Just trying to think of a way to achieve this.
I want each character (of the same character) to aim towards the nearest object, if that object has already been aimed at by one of the characters I want them to aim at the next closest available object of the same type.

So far:
I have a number of the same characters trying to pick up the same item (i dont want this because...). For example in a room full of chests 3 identical characters try to take one treasure chest. I need to reduce the chest count when collected but instead of just taking a -1 since all 3 characters get to it at the same time they –3 from the count instead of -1. this leaves just one chest removed and -3 from the count.

In short i am doing this:
For each character on the screen i am picking the closest chest and moving the character to it. If that chest goes before the character arrives (e.g. player collects it) then the character picks the next closest chest etc. The problem happens when several characters overlap and get close to a chest. I have the events triggered on a distance the character gets to the chest, so when they are a certain distance it triggers certain events, and when very close the chest is seen as picked up so destroyed and minus the chest count etc.

i am using the pick nearest for character movement but this is where the problem lies in that more than one character can pick the same chest to aim at causing the issue. I was trying to think of a way to use the UID of the chests and not to let the characters pick it if the previous character has already spotted it and assigned it to an instance variable, but cant seem to see how to work that in construct.

If anyone has any ideas, would be helpful.

Thanks
Some games: https://play.google.com/store/search?q= ... s&hl=en_GB Feel free to show the panda some support, he would appreciate it :)
B
19
S
5
G
1
Posts: 155
Reputation: 1,619

Post » Mon Oct 06, 2014 10:13 am

You shouldn't have to keep track of the number of chests to make it work. Your idea of using pick nearest is the way to go as you can use this to pick the nearest, second nearest, third nearest and so on. However to do it you need some way to exclude chests from being picked as the nearest. Which you can do by using a variable "Interact_UID" for the chests.

So to make it work you could do something like this:

Set chest as target for character
Condition:
for each Character (We need the for each at top, as we want to make sure that chests picked by Chest.interact_UID = 0 gets updated for each Character)
Chest.Interact_UID = 0 (Means that no character have currently targeted the chest)
Pick nearest Chest to character

Action:
Set Chest.Interact_UID = Character.UID (Now the chest have been targeted by a character. And the interact_UID is set, so no other can select it.)

Get character to pick up chest
Condition:
Chest.Interact_UID > 0 (Its very unlikely that any of your characters have UID of 0 so this should work)
For each Chest
Pick Character UID = Chest.Interact_UID


Action:
Character (Move to Chest)

When the character arrives you just need to make it so its the correct character that picks it up. To do that best, depends on what type of movement you are using, Path finding, Per tick etc.

The best thing to do, if you need the characters to do a lot of different automatic actions is to make some kind of state machine if you don't already, otherwise you will most likely end up loosing control and have a very hard time getting characters to behave correctly.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Mon Oct 06, 2014 2:24 pm

Thanks for the reply.

I think this is pretty much what i have set up, but am using a boolean to change the state of the chest.
I am spawning characters which have the bullet behavior and then setting their angles to the chest they have picked. If no chest in sight then they do something else until a chest does come into sight.

I have something like this:

for each character that hasnt picked up a chest
chest/pick nearest to character (pick nearest one to character)
chest/chestFALSEchosen (has the picked chest already been chosen by a character)
character has LOS to chest
----- action ---- chest/set chosenTRUE (set boolean on chest to have been chosen)

chest has NOT been picked up by player
chest chosenTRUE (chest has been chosen by a character)
character has LOS to chest
----- action ---- character rotate angle towards chest (set the character towards that chest)

(sub events under the above)
stuff when the character gets within certain distances do certain things
when character is on top of chest set the picked up boolean to TRUE
add the chest count variable
destroy the chest

what seems to be happening with that is the spawned characters are still able to be given the same chest to aim at, if i collect it first they then aim at the next closest chest to them.

what i need is pick nearest that hasnt already been picked then move onto the next nearest if it has, but i dont think the picknearest is behaving like that.

Under the For Each Character at the top of this page, If the condition of "chest chosen" is TRUE in the same block (where it should be false to get the action to work) then I think it skips the action part associated, which is why i was thinking of storing and comparing the UID of the chests etc At the moment all characters seem to be picking the closest chest to them no matter what.
Some games: https://play.google.com/store/search?q= ... s&hl=en_GB Feel free to show the panda some support, he would appreciate it :)
B
19
S
5
G
1
Posts: 155
Reputation: 1,619

Post » Mon Oct 06, 2014 4:41 pm

chest has NOT been picked up by player
chest chosenTRUE (chest has been chosen by a character)
character has LOS to chest
----- action ---- character rotate angle towards chest (set the character towards that chest)


But you need to make sure that its the correct character and chest that gets picked, in this case it can be any character that have LOS to a chest which have been chosen.

(sub events under the above)
stuff when the character gets within certain distances do certain things
when character is on top of chest set the picked up boolean to TRUE
add the chest count variable
destroy the chest


If the main event is not picking correctly then this will not work correctly either. So when you fix the main event then you can fix this one as well. As you should then have the correct character and chest selected.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Mon Oct 06, 2014 5:27 pm

Here is a graphic of what I have set up as basics, hope that sheds some light on what I am doing wrong.

example.jpg
You do not have the required permissions to view the files attached to this post.
Some games: https://play.google.com/store/search?q= ... s&hl=en_GB Feel free to show the panda some support, he would appreciate it :)
B
19
S
5
G
1
Posts: 155
Reputation: 1,619

Post » Mon Oct 06, 2014 6:02 pm

To me it looks like it would be better to split it up in to 3 events. Because that way you can lock the chest to an character more easily and it makes it easier to program.

1. An enemy that is currently not picking up a chest need to find one to pick up.
Con:
For each enemy
Chest is not Chosen
Enemy have LOS to chest

Action:
Chest chosen = true

(However you need to make sure that the enemy doesn't pick up everything. So we alter it a bit.)
Con:
Enemy.interact_UID = 0 (So if the enemy currently doesn't have a chest targeted it will look for one)
For each enemy
Chest is not Chosen
Enemy have LOS to chest

Action:
Chest chosen = true
Enemy.interact_UID = Chest.UID


2. When the enemy have found a chest to pick up it will rotate towards target. (This is a new event)
Con:
Enemy.interact_UID > 0
For each enemy
Pick Chest by UID = Enemy.interact_UID

Action:
Enemy rotate 10 degree towards (Chest.x,Chest.y)

3. When reaching the chest it will pick it up (This is also a new event)
Con:
Enemy.interact_UID > 0
For each enemy
Pick Chest by UID = Enemy.interact_UID
Distance(enemy.x, enemy.y, chest.x, chest.y) < 10

Action:
Chest destroy
Enemy.interact_UID = 0 (So it can pick up a new chest)
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,838

Post » Tue Oct 07, 2014 10:40 am

Thanks for your help talking this through.
Think I have it working now, Just testing all the numerous states it can go wrong in.
Some games: https://play.google.com/store/search?q= ... s&hl=en_GB Feel free to show the panda some support, he would appreciate it :)
B
19
S
5
G
1
Posts: 155
Reputation: 1,619


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests