Enemy should chase player only when they're on the same platform?

0 favourites
  • 5 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • In my platformer game, I want the enemies to chase the player when:

    1) They are within range of the player (e.g., within 500 pixels)

    2) they are on the same platform as the player

    I can implement 1 with the LOS behavior, but that also makes the enemies follow the player if the player is on other platforms nearby. E.g., when the player walks underneath the enemy's platform and is within 500 pixels of the enemy, the enemy follows the player's movement.

    I've thought of an approach where each platform has an ID, and any enemy on that platform has the same ID, and when the player touches the platform they get that ID, etc, but that will get cumbersome quickly with lots of enemies and platforms. Is there a better way to do this? I'm sure it's been done many times before.

    Thanks

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Make the LOS a cone in front of the enemy instead of a circle with 'cone of view'. Something like a 45 degree size might do.

  • Thanks. The challenge I've had w/ the LOS cone is that it only works for forward facing enemies. I.e., if I set the cone to be in the direction the enemy is facing, I can basically walk up behind them and I won't be in their LOS.

    I'm trying to implement a somewhat intelligent enemy AI, specifically:

    - they'll 'see' me from far away if they're facing facing me

    - if they're not facing me, they'll 'see' me when I'm closer, but I don't need to be right on them

    - if I shoot them from behind, they instantly know I'm there, regardless of how far away from them I am

    I guess this isn't really what LOS behavior is meant to accomplish, and it's more useful when trying to hide behind solid objects, etc. Just wondering if I'm missing something.

  • You can set up 2 or as many los cones as you want, facing the directions you want, with the distances you want.

    Or associate the player and the enemy objects by storing the uid of the platform they are touching in an instance variable. If they match, do the thing.

  • You can set up 2 or as many los cones as you want...

    Ok now THAT I didn't know - gonna try it!

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