Pathfinding and multiple instances

Get help using Construct 2

Post » Thu Mar 14, 2013 7:26 pm

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?



ImpulseCollision.capx
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Thu Mar 14, 2013 7:43 pm

[QUOTE=Excal] 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?
[/QUOTE]

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.vee412013-03-14 19:43:56
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Thu Mar 14, 2013 7:52 pm

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?
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Thu Mar 14, 2013 8:44 pm

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:



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.Excal2013-03-14 21:32:53
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 23 guests