Can't figure out enemy behavior on a grid.

1 favourites
  • 5 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Good evening!

    Here's the hacked-together mess of a game so far:

    The player moves the blue square around a block maze. Graphics are amazing. Player can't handle the level of realism.

    Here is my attempt at the enemies' basic AI, characterized by the red squares, because for some reason red equals bad:

    It is atrocious and complicated and only sort of works, in that the enemies will crawl, cell by cell (16 x 16px) toward whatever the player's X and Y coordinates are. But it has some issues which is why I'm posting here, as well as lighting black voodoo candles to wish for programming skills.

    Here's what I want it do:

    - Enemies go toward the player by one square every second or so, up down or diagonally.

    - It's okay if the blocks easily thwart the enemies. Luring them behind a block to stop them is part of the strategy.

    - They use the "grid" background squares' "Covered" instance variable to check if it's open.

    - Enemies treat each other as obstacles and do not overlap.

    Here's what it actually does:

    - The enemies, when going diagonally, they can spit in the face of physics and overlap blocks. The "grid" object's instance variable is being ignored and moving to the space anyway.

    - The enemies seem to love each other. Once they overlap they stick together and act as one.

    I hope somebody out there can think of an event type that I am ignorant to. I also hope my goals aren't too lofty as I just want these enemies to be brain-dead monsters that run into walls. MAYBE implement something that, if they're stuck, try a random movement along the other axis to try and break free.

    Finally, here's the capx:

    https://drive.google.com/open?id=1ZQFji-wKQ05A4L-0aluGT8IFli_lUwiW

    Thank u all my sweet babies

  • First of all, use "For each enemy" event under the "Every 1 second".

    You shouldn't check if enemy is overlapping enemy, because.. just because. Create a family EnemiesFamily with the Enemy sprite, and change your events to "Enemy is overlapping EnemiesFamily", this way you can refer to both instances in the event separately - overlaper and overlapee..

    Also, take a look at Rexrainbow's addons for grid-based games:

    construct.net/en/forum/extending-construct-2/addons-29/plugin-board-layout2board-beha-47187

    Moveto behavior to easily move enemies from one tile to another:

    construct.net/en/forum/extending-construct-2/addons-29/behavior-moveto-40701

    Pathfinding for grid:

    construct.net/en/forum/extending-construct-2/addons-29/behavior-easystar-js-pathfindi-96215

  • Thank you, I really appreciate you taking the time to look at my project.

    Among the links you sent, do you think using RexRainbow's plugin set would be sufficient, or will I need to utilize both that and the Moveto plugin as well?

  • I never used Rex's rex_grid_move plugin, but seems like it's what you need.

    I recommend installing MoveTo anyway, it's a very popular and versatile behavior.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So I took the advice of dop2000 and installed RexRainbow's addons.

    To my surprise some of the things I wanted to do were surprisingly easy, and yet one or two still elude me.

    Right now I'm trying to have the GridMove behavior grab the closest blocks to the Player and push them (only Up for now till I get it working). Problem is that it moves all of them even if there are gaps in between. I know what I want it to do but I cannot think of how to express this logic in Construct.

    Hopefully somebody has a better understanding of this and can help. The blocks should only move if the Player or another Block moves into them.

    Here's the capx just in case:

    https://drive.google.com/file/d/1nMMugT-i-ea9h0Jf3py13wAiWzbLxlVN/view?usp=sharing

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