How do I make EnemyAI chase player with Gridmovement

  • I am currently using this for grid movement

    dir = 0

    step_timer = 0

    speed = 1

    grid_size = 32

    The player and Enemy moves in a 32x32 grid, one box at a time. The AI is currently Automoving where it chooses either 0, 90, 180 or 270 for its dir value randomly every second. I am trying to make a Line of Sight behaviour for the EnemyAI to chase the player

    Right now i have it like this

    EnemyAI X < Player.X = EnemyAI set dir to 0 Moving right

    EnemyAI X > Player.X = EnemyAI set dir to 180 Moving left

    EnemyAI Y < Player.Y = EnemyAI set dir to 90 Moving down

    EnemyAI Y > Player.Y = EnemyAI set dir to 270 Moving up

    However the EnemyAI suddenly reaches a point where its just standing still and the animation keeps lookin up and down. I think the 4 codes are overlapping eachother in some bad way.

  • If you think that conditions are overlapping, try adding "else":

    EnemyAI X < Player.X = EnemyAI set dir to 0 Moving right

    Else

    EnemyAI X > Player.X = EnemyAI set dir to 180 Moving left

    Else

    EnemyAI Y < Player.Y = EnemyAI set dir to 90 Moving down

    Else

    EnemyAI Y > Player.Y = EnemyAI set dir to 270 Moving up

    If this doesn't help, could you share your capx?

  • I could not get it to work with "Else"

    I am not sure if i can share a capx directly through a reply, but i tried uploading it here

    ufile.io/hqr5a

  • Did you upload windows shortcut file - DeadByRicki.lnk?

    Please save you project as a single file in C2 and upload the capx file.

  • drive.google.com/file/d/1o470Dn ... sp=sharing

    I think you can download it from my google docs folder. <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ...and now your link is invalid (shortened).

    Try posting it without the "https://" part

  • drive.google.com/file/d/1o470Dn9pt2kWpKOwqSnVmt7bR77qe1EP/view

  • https://www.dropbox.com/s/c1eixd9c58aib ... .capx?dl=0

    Among other things I increased LOS range, otherwise enemy never has LOS to Jeff. Now it's chasing Jeff straight away.

    Angle 0 in Construct2 is at the right, so all sprites should be facing right, that's why I turned your EnemyAI image.

    Also you are using tiled background wrong. You should not have hundreds of instances of tiled background! Just put one instance on the layout and resize it.

    If you want different tiles with different grass, use TileMap object instead. But again, you need only 1 instance of tilemap with 300 tiles, not 300 instances with 1 tile each <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Thank you! works great even though i have no idea what abs is. I wanted to make my own "Dead by Daylight" game and im sure it'll be great haha.

  • https://www.scirra.com/manual/126/system-expressions

    Abs basically removes negative sign from numbers.

    abs(5)=5

    abs(-5)=5

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