Pathfinding and multiple instances

0 favourites
  • 4 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Is there a way to make pathfinding prioritize one or any instance of an object?

    For example, in my space game I have multiple enemies that will be in different locations. When I have an ally ship spawn, I want it to focus one or any of these enemies and start chasing it. I have it set to find a path to Enemy.X, Enemy.Y, but since there are multiple enemies in play, the pathfinding fails to work.

    Is there a way to have pathfinding pick one particular instance of an object to follow?

    <img src="http://i.imgur.com/LEI7v3x.png" border="0">

    ImpulseCollision.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is there a way to make pathfinding prioritize one or any instance of an object?

    For example, in my space game I have multiple enemies that will be in different locations. When I have an ally ship spawn, I want it to focus one or any of these enemies and start chasing it. I have it set to find a path to Enemy.X, Enemy.Y, but since there are multiple enemies in play, the pathfinding fails to work.

    Is there a way to have pathfinding pick one particular instance of an object to follow?

    You'll need to define a condition to pick with; do you pick the closest enemy, most dangerous enemy, random enemy or with what criteria you wish to pick the enemy with? I recommend you take a look at the 'picking' section at FAQ thread, as at the moment you are applying same actions to all AllyShips and targeting the 'first' enemy at the list of picked enemy objects.

  • I think I get a better idea of it now.

    Basically each instance would have an instance variable. Each time an instance is created, this instance variable would increase by 1, this way each different instance has a different number for this variable.

    So in this case I would need to:

    -Check which instances exist on the current level.

    -Check the distance between the ally ship and each enemy ship.

    -Find a path to the closest one.

    Does this sound right?

  • Right now I have each enemy update the instance variable upon creation.

    For example, when an enemy is created, the EnemyID instance variable is set to its UID.

    Now I'm not sure how I would check which enemy instances exist on the current level (since they can be destroyed). Do you have any ideas on how I could check for that?

    UPDATE 1: I'm currently running a For-Each loop that (from what I think) should run through each EnemyID that is currently on the level:

    <img src="http://i.imgur.com/8NIZEPf.png" border="0" />

    Is this correct? Would this run through each enemy on the level? If so, then the next step is figuring out how to determine which enemy is closest to the ally ship. I have a variable called ClosestEnemy but I'm not sure how I would actually check for the closest enemy.

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