How do I choose a specific instance based on lineofsight

Get help using Construct 2

Post » Thu Jan 14, 2016 12:25 am

So, I have an AI that pathfinds towards another AI and attacks them.

The hunted AI is spotted by the hunting AI it sets an instance variable called PursuitDetection to one on the hunting AI. Every 0.5 seconds PursuitDetection is equal to one, it is supposed to find and move along a path towards that specific hunted AI that was detected. The problem is that the pathfinding selects a random hunted AI on the whole layout.

Is it possible to, when setting a target for the pathfinding, to select the closest 'hunted AI'.X and 'hunted AI'.Y to the hunting AI?
B
28
S
11
G
4
Posts: 77
Reputation: 4,321

Post » Thu Jan 14, 2016 4:08 am

Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
71
S
19
G
8
Posts: 640
Reputation: 9,701

Post » Thu Jan 14, 2016 4:26 am

Kind of confusing to me, but I have another problem that involves setting the angle of something every tick towards another instance, but it selects a random instance.

So is it possible to select the closest instance to the player somehow? Like when you select the action it asks for an X and Y coordinate.

Is there a way I could select the closest of that instance relative to the player through that?
B
28
S
11
G
4
Posts: 77
Reputation: 4,321

Post » Thu Jan 14, 2016 5:04 am

Try this, under the sprite you want the nearest picked of, choose Event "Pick Nearest/furthest"
Set the X & Y to the X & Y position of your player.

Looking through examples I've posted in the past, there is also the turret behavior, that you could use to set the angle when the target is within range:

https://dl.dropboxusercontent.com/u/854 ... Range.capx

(this example is like zombies turning toward the player when within range, and slowly moving that direction.)
B
242
S
63
G
33
Posts: 903
Reputation: 40,756

Post » Sat Jan 16, 2016 1:43 am

Paradox wrote:Try this, under the sprite you want the nearest picked of, choose Event "Pick Nearest/furthest"
Set the X & Y to the X & Y position of your player.

Looking through examples I've posted in the past, there is also the turret behavior, that you could use to set the angle when the target is within range:

https://dl.dropboxusercontent.com/u/854 ... Range.capx

(this example is like zombies turning toward the player when within range, and slowly moving that direction.)


Thank you so much! :D
B
28
S
11
G
4
Posts: 77
Reputation: 4,321


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 28 guests