Better Enemy AI Pathfinder Movement?

  • My enemy sprites are using the pathfinder buts it's not very smooth. They keep stopping randomly and colliding with things when they shouldn't. I suspect this is due to the animation sprite (which is pinned on top) being a lot bigger than the base sprite, meaning it's stops, not because of the base sprite but because the animation sprite on top colliding with a solid for example. I'm not certain that this is the reason though.

    I have included an image link below to show a possible solution I though might make a positive difference and produce better functionality with the enemy sprite as a whole. Will the movement and rotation work better, and with the fighting can the player and enemy bases overlap to preform collision hits with the animation sprites?

    Number 1. is my original base and animation sprites and 2. is a bigger base sprite filling the height and width of the animation sprite. Can this second option work better for pathfinder?

    Also just out of interest is pathfinder a bit touch and go? Its quite new if I'm not mistaken.

    Image link: ibb.co/S7ryyw0

  • This method of using a base sprite + animation sprite is specifically intended to prevent issues like this. Your base sprite should handle all movements and collisions, you should remove all behaviors (like Solid, Platform, Pathfinding etc.) from the animation sprite.

    And yes, the base sprite should be approximately the same size as the animation sprite, maybe a bit smaller/narrower.

  • Ok so Ive done that. The animation sprite didn't have any behaviours with it except for Pin. The enemy sprite (base) still struggles to consistently go to the player and stops every so often. I have included a GIF image link to give a clear visual..

    Player - PINK

    Enemy - BLUE

    Gif Link: ibb.co/7Q0QG6c

    Event Sheet Screenshot: ibb.co/3YMy5Dt

  • I think the problem is with MoveTo behavior - it's disabled. When you disable Pathfinding, you need to enable MoveTo.

    Also, you probably shouldn't check LOS on every tick, do it every 0.5s or so. Otherwise when both sprites are moving, your enemy will switch back and forth between Pathfinding and MoveTo at the edge of LOS range.

  • Wow it works perfect now! Enemy AI is a lot smoother. Thanks a bunch!!

  • Quick question. My LOS doesn't seem to have an effect now, even tho the enemy is running smooth. Because the enemy is finding path to player every 0.5 seconds, the LOS event is irrelevant. I'm looking to have the enemy react when the player is in range and not just react when the layout starts.

    I tried placing that event (7) in the same loop as the LOS event (4) (so the enemy only finds path to player when player is in sight), but that made the enemy a lot less smooth like it was initially. He stops at an obstacle and doesn't find his way around, even if the player is getting further away?

    Image: ibb.co/m00sDyF

  • No, what I meant is this:

    If you want the enemy to react faster to player movements, try a smaller value in "Every X seconds"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok I tried that (which makes sense), but despite the enemy moving around very smoothly, he still struggles to work his way around an obstacle to reach my player. I have included a link to the updated visual and a link to the event sheet.

    GIF visual: ibb.co/L0NG694

    The enemy (blue) is initially moving along path

    When player (black) is in LOS, the enemy turns and chases

    But when my player goes north of enemy (past the obstacles), the enemy 'crashes' into the obstacle and STAYS there, instead of moving around them to get to the player, like a person would.

    Is this just a LOS thing or is there more to it?

    Event sheet: ibb.co/ZHd7k6v

    I've adjusted the 'Every 0.5 seconds' down to 0.4 seconds but it doesn't really do anything to help.

  • Done it! Just replaced the Move To with Pathfinder when player is in LOS. Enemy AI is much better now.

    GIF Visual: ibb.co/hYjxrHp

    Event Sheet: ibb.co/HYWcRgW

    :)

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