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

0 favourites
  • 4 posts
From the Asset Store
10 turrets rendered in 3D with top down and menu views. Three upgrade levels per tower.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • Working example:

    https://

    drive.google.com/open?id=0B1SSuCVV8v74NV9Odmg0Wm1wMkE

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)