How do I make enemies follow a player?

0 favourites
  • 7 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • 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

  • Bumping this, because it's been a while.

  • Anybody at all know what I did wrong? I'm still trying to figure it out and would greatly appreciate the help!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • The logic looks reasonable but we would probably need a project file to look at.

  • 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.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)