# Move to location and search

Get help using Construct 2

### » Sun Apr 28, 2013 11:30 am

Any thoughts on the following would be kindly welcomed.

Working on the AI for a top-down stealth outing. I'm looking at a pattern of behaviour for a resident of a house who - on "hearing" something moves to that location. What I have in mind is an enemy AI - who being in proximity to the player, moves slowly / cautiously to the point in 2D space where the player came within a particular proximity to them - say 100 pixels. Moving cautiously should give the player time to evade. Once the enemy reaches the point where the proximity routine is tripped / noise is heard - they'll wander about, look around, and if the player is not in line of sight - they'll resume their duties.

Problem is working out how to get to that point in space - so they can wander about / look around as opposed to acquire the player and chase.

Cheers
B
7
S
2
G
3
Posts: 7
Reputation: 3,185

### » Sun Apr 28, 2013 2:08 pm

have you checked out the pathfinding behaviour?
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Mon Apr 29, 2013 11:37 am

@keepee - yep, on pathfinding. Thanks. Along those lines - how how might you specify the X and Y coords for the enemy to "find path to" as the point in 2D space where the player tripped the proximity threshold around the enemy.

Maybe another way of asking the question is - how do you get the enemy to find path to a point where the player was - but no longer is?
B
7
S
2
G
3
Posts: 7
Reputation: 3,185

### » Mon Apr 29, 2013 1:31 pm

won't it just be 'find path to player.x, player.y' ?

as long as you only run that action when the player is heard or seen it should work..

if you want to create a more complex behaviour though, for example after the enemy arrives at the point, for it to search around that area... you'll probably want to store the player.x/y to variables like:
enemy.lastSeenX
enemy.lastSeenY

that could act like a kind of anchor point for a search area
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Tue Apr 30, 2013 10:57 am

Player.x, player.y provides a regularly updated set of coords to the enemy to track the player down. Those coords are where the player is at every point in time. So rather than pointing the enemy at where the player was a point in time that has past, it points them at where the player is presently.

Thinking out loud here - but maybe I need to continuously track player x and y coords all the time. And have the enemy move to that most recent set of stored coords (in an instance variable?) which are made available to it only when the proximity threshold has been reached.

But how....? How to make the enemy move to a specific point (X,Y) once and only once the player has come within so many pixels....

I can't quite crack it, but I reckon it'll be so obivious a solution once it's sorted
B
7
S
2
G
3
Posts: 7
Reputation: 3,185

### » Tue Apr 30, 2013 9:57 pm

that's what i meant by this:

[quote=keepee] as long as you only run that action when the player is heard or seen it should work.. [/quote]

as long as the action to find the path to player.x/player.y is only run when the player is heard or seen.. aka not every tick
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Return to How do I....?

### Who is online

Users browsing this forum: Google [Bot], Nexis717 and 20 guests