Trying to tweak attack AI

Get help using Construct 2

Post » Sat Jan 18, 2014 10:14 pm

Here are the events I use to make the enemies attack when within range of the player. Can I be more specific between the x and the y meaning, could I have the attack happen when the enemy is within 200 pixels of x and 50 pixels of y?

Image
B
20
S
4
Posts: 382
Reputation: 2,984

Post » Sat Jan 18, 2014 11:42 pm

I'm not sure what are you looking for... however

Use Instance variables for each sprite while comparing the distance.
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Sun Jan 19, 2014 3:24 am

What Joannesalfa said. Also, as far as I can tell, you don't need to check the distance between your enemy and the player twice, just go 'else' for the second condition.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Sun Jan 19, 2014 7:09 am

The distance() function wont distinguish between different x and y target values, so don't check that way.

instead, directly compare the x values and the y values. Since the enemies can be on either side and above or below, you could end up with either positive or negative values. so, use the ABS() function (which returns the absolute value, always positive).

So, where you have the first sub event where you check Distance, replace that with:

System: Compare two values: ABS(BoxWalker.X - BoxPsi.X) <= 200
then add another condition:

System: Compare two values: ABS(BoxWalker.Y - BoxPsi.Y) <= 50


and, as TiAm said, then later use ELSE where you have the second Distance() function.
B
98
S
34
G
20
Posts: 438
Reputation: 17,825

Post » Sun Jan 19, 2014 4:35 pm

Great suggestions. Changed condition to else and did as you said AllanR - Thanks!
Image
B
20
S
4
Posts: 382
Reputation: 2,984


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, kainrazial and 6 guests