[Solved]AI and pathfinding distances

Just started using Construct 2? Post your questions here

Post » Mon Mar 20, 2017 2:55 pm

Hello folks,

Hopefully someone can help me with this.

Basically, my issue is that the Enemy's do not stop pathfinding or movement when they get within a certain distance to the player. As far as I can tell the math is sound, it's a simple check to see if the distance is less than 5000 and greater than 450.
Another check to see if it's less than 450 should stop the movement.

Please note that the path finding TO the player works as expected

Code is below, hoping i've missed something basic but if not, any suggestions?

Cheers,
Matt

Image
Last edited by AM_Games on Mon Mar 20, 2017 7:30 pm, edited 1 time in total.
B
9
S
2
Posts: 69
Reputation: 833

Post » Mon Mar 20, 2017 4:57 pm

Hmmm?

What I see is your use of on pathfinding path found move along in line 284 is probably over riding your order to stop moving in line 285.

I would add a global variable trigger to that to to stop the pathfinding completely when that distance is met.

That should fix the problem.
Banned User
B
27
S
7
G
58
Posts: 1,229
Reputation: 34,790

Post » Mon Mar 20, 2017 5:48 pm

283 & 285

You dont pick any EnemyShip in those 2 events. So they are un-referenced, which is the same as a 'pick all'.
So, they all (each and every one) find a path every second (not that good for performance too) ...
And, they all (each and every one ) stop when the condition is somehow true.

System > Compare two values is only a logical condition, it has not 'pick' function.

You need a 'for each enemy', but then you surely have to bundle 283 & 285 in one 'for each', else you gonna drop performance to turtle walk in the end.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Mar 20, 2017 7:30 pm

Thanks lads, sorted now.
Looks like it was me being a bit special and not noticing I hadn't added a pick condition.
@Lamar
Done, thanks!
@99Instances2Go
Thanks for pointing that out, i'll switch it to individual instances on screen (or close)
B
9
S
2
Posts: 69
Reputation: 833


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests