Checking for Destroyed Objects.

Get help using Construct 2

Post » Thu Apr 04, 2013 4:58 am

I want to know if there is a condition which checks if all instances of an object are destroyed.

I'm trying to set AI for my enemies to hunt down specific NPC classes one by one in order,

eg: | System: Every tick | Enemy1: Set Angle Toward: NPC1.X NPC1.Y
     | NPC1: is Alive     |     
   

Alive: is a boolean which detects if the NPC1 health is equal to or below zero.

What I want it to do, is after all instances of NPC1 are destroyed (Alive = False) My enemy AI switches to follow NPC2.


I tried by doing;

    | System: Every tick | Enemy1: Set Angle Toward: NPC2.X NPC2.Y
    | NPC1: X is Alive   | (Inverted)


I'm not sure why this didn't work, since I have another event in my sheet which says:

    |NPC1: X is Alive| NPC1: Destroy.

And that works. But when I add the boolean condition onto another it seems to not work




On a separate question, is there a way to;

Set Angle Away From Position?

Before you say "invert the values" I want to use this to set my "NPC's" to run away from the Enemy's. ATM I just have them all running in Random(360) directions. Since inverting the values only works for unchanging values, is their an equation or action or something that inverts the values for me?


Sketchy772013-04-04 05:33:02
B
15
S
2
Posts: 29
Reputation: 887

Post » Thu Apr 04, 2013 6:49 am

[QUOTE=Sketchy77] I want to know if there is a condition which checks if all instances of an object are destroyed.
[/QUOTE]

From system-> compare two values condition: sprite.count = 0. That would check if any instances of the object exist. sprite.count is built-in variable that keeps count of how many instances of an object exist.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Thu Apr 04, 2013 7:26 am

Thank you so much. That worked perfect.

Any Idea about my other question?


[QUOTE=Sketchy77]
On a separate question, is there a way to;

Set Angle Away From Position?

Before you say "invert the values" I want to use this to set my "NPC's" to run away from the Enemy's. ATM I just have them all running in Random(360) directions. Since inverting the values only works for unchanging values, is their an equation or action or something that inverts the values for me?
[/QUOTE]
B
15
S
2
Posts: 29
Reputation: 887

Post » Thu Apr 04, 2013 7:38 am

[QUOTE=Sketchy77]
On a separate question, is there a way to;

Set Angle Away From Position?

Before you say "invert the values" I want to use this to set my "NPC's" to run away from the Enemy's. ATM I just have them all running in Random(360) directions. Since inverting the values only works for unchanging values, is their an equation or action or something that inverts the values for me?
[/QUOTE]

Don't know what behavior (if any) you use for movement, but in general this should work:

enemy set angle towards position: player x,y
enemy set angle: enemy.angle-180

Or alternatively, if you prefer single action:

enemy set angle: angle(enemy.x, enemy.x, player.x, player.y) - 180
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Fri Jul 05, 2013 1:39 pm

Thanks a lot for the Sprite.count=0 trick !
B
8
S
3
G
2
Posts: 35
Reputation: 2,177


Return to How do I....?

Who is online

Users browsing this forum: mercuryus and 17 guests