How do I make enemies follow a player?

Get help using Construct 2

Post » Sun May 15, 2016 2:28 pm

I'm trying to make my enemies go to the player when they are in its line of sight, but it doesn't work. Here's a screenshot of the portion that is supposed to do that:
http://prntscr.com/b4b3oe
http://prntscr.com/b4b3xs
B
5
Posts: 5
Reputation: 225

Post » Sun May 15, 2016 11:22 pm

Bumping this, because it's been a while.
B
5
Posts: 5
Reputation: 225

Post » Mon May 16, 2016 7:54 pm

Anybody at all know what I did wrong? I'm still trying to figure it out and would greatly appreciate the help!
B
5
Posts: 5
Reputation: 225

Post » Tue May 17, 2016 10:39 am

The logic looks reasonable but we would probably need a project file to look at.
B
47
S
18
G
84
Posts: 2,271
Reputation: 49,796

Post » Tue May 17, 2016 12:59 pm

I dont get the logic.

For a 'every X seconds' to work its needs to check its time kinda every tick.
Lets say its must fire every 2 seconds. First tick it sets that time, next ticks its askinig the system "is it time yet". And when it reads 2 seconds, it will fire and reset the clock.

You would do the same, keeping an eye on that watch.

A function gets called. Then it runs one moment. The containing events and actions dont get called/checked/compared/activated again till the next call. So that 'every x seconds' aint gonna do one thing.

If you need that timer, use a real timer. Outside the function. Thats a behaviour. Start a timer with a specifiek tag in layout start up. Use a 'on timer' condition. And bring in there that whole on locate function. No need to call it, it calls itself when it is time. The on failed path is then not needed to.

If you want it to it to find a path 2 second after it has sight on the player. Then make the 'has LOS' a top event. And start the timer in there. Make the inverted to stop the timer.

'on arrived' is not needed, because the timer will catch that.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed May 18, 2016 2:01 am

99Instances2Go wrote:I dont get the logic.

For a 'every X seconds' to work its needs to check its time kinda every tick.
Lets say its must fire every 2 seconds. First tick it sets that time, next ticks its askinig the system "is it time yet". And when it reads 2 seconds, it will fire and reset the clock.

You would do the same, keeping an eye on that watch.

A function gets called. Then it runs one moment. The containing events and actions dont get called/checked/compared/activated again till the next call. So that 'every x seconds' aint gonna do one thing.

If you need that timer, use a real timer. Outside the function. Thats a behaviour. Start a timer with a specifiek tag in layout start up. Use a 'on timer' condition. And bring in there that whole on locate function. No need to call it, it calls itself when it is time. The on failed path is then not needed to.

If you want it to it to find a path 2 second after it has sight on the player. Then make the 'has LOS' a top event. And start the timer in there. Make the inverted to stop the timer.

'on arrived' is not needed, because the timer will catch that.


Thanks for replying! I understand what you're saying, and I guess I don't need the timer. So I removed it, which makes my code better, but the enemies still don't follow the player. Do you know how I could fix it? Would having the file help, like the other person asked for?

Edit: I'll upload the file tomorrow.

Edit 2: And I should mention, when I removed the timer I moved the actions that were on it to the event above it.
B
5
Posts: 5
Reputation: 225

Post » Wed May 18, 2016 7:56 am

Yes, a capx would help everyone.

At the moment still 3 posibilities open.

1/ The buggy insects are solids and you have the behaviour set to avoid solids.
2/ The buggy insects are not solids, but there are solids in play, and cellsize & -border are set so it does not get past them.
3/ You call the pathfindig to much/to fast. It takes time to find a path. If you call it to fast again, it will not finish, but start over. Over and over again. Without ever having the time to find a solution.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 31 guests