How do I deal with multi-faction AI detection?

0 favourites
  • 6 posts
From the Asset Store
Detects any kind of ad blocker. Very easy implementation into already existing projects
  • Hello everyone,

    In my game I have multiple factions. And they basically have some friendships and hostileships.

    So basically enemies are like this:

    F1 > F4

    F2 > F3

    F4 > F1 and F3

    F3 > Everyone.

    Now in my setup, I have an object (the actual enemy sprite) and a hidden "range" sprite as child that I create at runtime so can't pre-setup it. When an object enters range, I'd like to detect which faction it is + which faction I belong to and see if it matches an enemy.

    The only way I can think of this happening is to have an "id" for each faction and then have variables like "enemy1, enemy2, enemy3, enemy4" and a "selfID" in the range object. Upon collision I compare if selfID is "F1" then ignore everyone but F4 from enemy1, enemy2, enemy3 and enemy4.

    But I feel this method is very crude and will end up breaking soon. Any ideas how I can tackle this so I can detect which kind of object entered and how I deal with it?

    Tagged:

  • I would probably use a pair of text instance variables, for example:

    Type="F2" (this enemy type)

    EnemyList="F1,F4,F5" (what enemies are hostile to this one)

    On collision with another enemy check if that's other enemy type is in the list using find(ThisEnemy.EnemyList, OtherEnemy.type) expression.

    Note, that this expression only works if you have less than 10 enemy types. Also, you might want to create a family and define these variables on the family.

  • I would probably use a pair of text instance variables, for example:

    Type="F2" (this enemy type)

    EnemyList="F1,F4,F5" (what enemies are hostile to this one)

    On collision with another enemy check if that's other enemy type is in the list using find(ThisEnemy.EnemyList, OtherEnemy.type) expression.

    Note, that this expression only works if you have less than 10 enemy types. Also, you might want to create a family and define these variables on the family.

    Huh, I can use lists as instanced variables on objects? How can I do that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I meant a string of text, which is a list (comma-separated) of enemy types.

  • I meant a string of text, which is a list (comma-separated) of enemy types.

    Oh, I see. I get what you mean. Yeah, that works Really well if "find()" would just simply find what I want. That is actually great. I didn't know I can do that.

    Thanks.

  • find() returns an index of the substring. So you need to compare find()>=0

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