Making turrets target objects based on team instancevariable

0 favourites
  • 6 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I have a problem.

    I have a game with many units, but each unit has an instance variable called Team which marks what team they are on.

    In this example, it's a space ship called SpaceFighter-- this is only one Object type. I do not want to clone this object type or make a duplicate object type, I want to do this using instance variables. There's two teams. Team 1 and Team 2.

    So there's two SpaceFighters.

    SpaceFighter 1 : Team = 1

    SpaceFighter 2 : Team = 2

    They fly around and also have a Turret behavior, it's great. However, adding targets has proven to be difficult.

    I obviously only want SpaceFighter 1 to target objects on Team 2 and not it's own team (Team 1), but I'm not sure how to do that.

    Does anyone have any ideas?

  • Going to try to get attention on this...

    One band-aid solution was

    Condition:

    On Target Acquired check to see if it was on the same team, and if it was,

    Action:

    Unacquire target.

    However, this led to the SpaceFighter targeting & untargeting itself and its allies 100 times per second with the off-chance that it will target an actual enemy.

    This solution is not good enough. Does anyone have a workaround for me besides duplicating the objects? I plan on having 4 players, 6 races, and 20 units each race. That's 120 objects-- if I have to make each object 4 times, that's 480 objects (and behaviors, effects, etc). I can't do that.

    Thanks guys.

  • Put the object into a Family, so you can reference the Targeter & Targetee.

    Use Pick by comparison (Targeter), where Team=1, Foreach, Pick by comparison (Targetee), where Team=2, Pick random instance. Have Targeter target Targetee.

    Do the opposite for Team=2, targetting Team 1.

  • Put the object into a Family, so you can reference the Targeter & Targetee.

    Use Pick by comparison (Targeter), where Team=1, Foreach, Pick by comparison (Targetee), where Team=2, Pick random instance. Have Targeter target Targetee.

    Do the opposite for Team=2, targetting Team 1.

    Hey, thanks for answering!

    I'm going to go ahead and give this a try in case I'm misunderstanding, but I don't think I comprehend the logic behind your conditions/actions. My intended outcome is to have MANY SpaceFighters on Team 1, 2, and possibly 3 and 4, and have the SpaceFighters target either nearest or first-in-range enemies. Would your suggested solution accomplish this? I guess the "pick random instance" is throwing me off.

    When I can, I'm going to try out your suggestion anyway.

    Thanks for responding btw, I spent an actual 4 hours trying to figure this out.

  • Here's three teams targeting the nearest "other" teams.

    http://www.blackhornettechnologies.com/ ... osest.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is really great and I will definitely be referring to this- thank you. I do wish I could use the Turret behavior, though, as I wouldn't be able to replicate predictive aiming.

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