Make duplicative AI skills

Get help using Construct 2

Post » Tue Dec 11, 2012 12:09 am

Hello world! :D

I am trying to make AI similar to 'http://www.verygaming.com/action/strike-force-heroes' and it's going pretty well so far.

This is the situation:
I have a main player sprite
I made hands with a gun positioned to player's shoulder, and which rotate in the player's direction if player is spotted.
I also made a sprite for the line of sight (to see if enemies see the player trough walls) which is also positioned to player's shoulder.
Then I made variables to the 'Line of Sight' for firing On/Off to make some bullets shoot when player is spotted.

There is no problem until I wanted to make more than one enemy of this type on stage: because I want hands to remain calm if player is not spotted, and line of sight has to follow him all the time, I cannot make it the same object.
And for example: Line of sight (enemy1) has Variable to "On" (means it spotted the player), all the hands read that variable and turn to the Player.

If I could just somehow make a single complex enemy who can be duplicated and maybe edited independently without having to make all the sprites all over again. Like a group or something, so that it has the same sprites, but not to read one another's variables.

I hope you understood my problem, I am not that great in Englis, but I gave my best to describe it to you.Euton2012-12-11 12:05:28
B
9
Posts: 10
Reputation: 1,271

Post » Tue Dec 11, 2012 3:01 am

I had this exact problem and what fixed it was making a 'For each' loop. So:

For each 'enemy' + line of sight 'On' > Rotate towards player + fire bullets + etc.

It was thankfully a very simple fix for me. If you still have trouble I will try to post a capx for you.
B
27
S
8
G
5
Posts: 429
Reputation: 6,902

Post » Tue Dec 11, 2012 12:44 pm

Thank you for a quick reply!

I tried what you suggested, but no luck... They still all look at the player as soon as the first line of sight is active. I tried all the combinations with 'For Each' action, even tried something with groups, but they can't tell the difference between their line of sight and someone else's, so they always look at the player as soon as one of them has Line of Sight set to "On"

I could try your .capx if it's not a bother for you to upload it

Cheers!
B
9
Posts: 10
Reputation: 1,271

Post » Tue Dec 11, 2012 1:07 pm

You could set them in a family and if one is in line of sight you set an instance variable up. You just need to choose the right children with something like:
-On line of sight collide(is over or anything else)
with family -> family.insight = 1

If you grant me your .capx I can do that for you.

But you could also sell it as a feature :D   
B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Wed Dec 12, 2012 4:54 pm

I checked out the families, and I think it wouldn't work that way either :/ But if you think you can figure something out, you could try it on this http://www.scirra.com/forum/c2enemy-line-of-sight_topic45095.html

If I could just make the "Enemy" object read only Variables from "Line Of Sight" objects connected to him alone, and not from the same "Line Of Sight" object that is connected to another "Enemy".

I could make it work for one and only enemy, but if I would like to duplicate him, it would all be messed up. Can I somehow limit Variables to only one group of objects, even if there are more than one instances of the same group?
B
9
Posts: 10
Reputation: 1,271

Post » Wed Dec 12, 2012 5:17 pm

You can make a variable in your 'LOS' object and call it something like "parent". When the 'LOS' objects are created, set the variable in each object to the UID (unique ID) of the correct 'Enemy' object. This way you can link the 'LOS' object to the 'Enemy' object and later use the variable to make sure the events only run for the correct enemy by comparing the variable and UID.
[code]+For each Enemy
-> Create object LOS on Enemy.X, Enemy.Y
-> Set variable parent to Enemy.UID[/code]
I made this example for someone yesterday, it's not about LOS specifically, but it covers the parenting principle:
EnemyHealthText.capx (r111)

Nimtrix2012-12-12 17:18:12
B
27
S
8
G
8
Posts: 903
Reputation: 8,452


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests