How do I keep 2 turrets from targeting the same object?

Get help using Construct 2

Post » Thu Apr 28, 2016 12:58 am

I know I need to reference the UID of the target but I can't figure out how to set this up. Help would be greatly appreciated
B
34
S
21
G
11
Posts: 9
Reputation: 8,576

Post » Thu Apr 28, 2016 1:17 am

Use a variable. =) Probably an instance variable in the target. When the target is acquired, set the variable to "targeted" or "target=true" etc. I assume by "targeting" you mean it has line of sight, so just pick the first LoS instance with a "Targeted" variable of "false" and set its UID in an instance variable belonging to the turret. When the line of site is lost, pick the same target referenced in the instance variable and set it's target variable to un-targeted or false. From there,only perform actions on line of site targets with targeted variables set to false. If it's true, keep searching. I'm not testing this in the editor, so feel free to post anything that doesn't quite work and I'll help tweak it.
B
17
S
7
Posts: 21
Reputation: 1,711

Post » Thu Apr 28, 2016 9:44 am

Turret has a 'has target' and a 'on target acquired' condition.
Turret has also the expression 'Sprite.Turret.TargetUID'

So, ''on target acquired' you can set Sprite.Turret.TargetUID to an instance variable of the turret. You just have to check first if there is no other instance variable of any other turret set with to that UID. Like this:

System > pick by comparisation > expression = sprite.variable > value = Sprite.Turret.TargetUID > object = sprite.
Then you check in a sub event if sprite.PickedCount = 0

If zero, you know there is no other turret with that target.

Then, to reset that variable to 'zero target', you use the 'has target' condition combined with an else to 'untarget' de variable.

Attention. The UID zero exist. If you have a sprite with UID zero, you will run into problems, when you set the variable to zero to represent a 'no target'. If you have a sprite combined with a turret with UID zero, then copy it in the layout, keep the copy and delete the original. UID zero is now gone.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Apr 29, 2016 10:42 pm

Working example:

https://
drive.google.com/open?id=0B1SSuCVV8v74NV9Odmg0Wm1wMkE
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: beohs and 13 guests