How do I create an entity that patrols items and follows the player in Construct 2?

0 favourites
  • 2 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • Can anyone help me implement an entity in Construct 2 with the following behavior?

    1. Patrolling random items

    - The entity should randomly choose an item scattered around the map to patrol.

    - It should move to the item and patrol around it for a random time (between 20-50 seconds).

    2. Following the player:

    - If the player enters the entity's field of view or radius, the entity should start following the player.

    - The entity should stop following the player when they leave the field of view or radius.

    3. Item switching:

    - After the patrol time is over, the entity should pick another random item on the map and start patrolling it.

    - This process of choosing and patrolling should repeat indefinitely.

    Additional Notes:

    - The player needs to collect the items, which get destroyed upon being touched. Therefore, the entity should avoid following items that have already been collected.

    - The same item sprite appears throughout the entire map.

    - The game is top-down.

    I've tried to do this on my own, but the entity barely moves, and I'm getting stuck. Any tips or examples on how to achieve this in Construct 2?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The way you do this in C2 is not much different from C3. Use LineOfSight, Pathfinding and Timer behaviors. On Timer event change the entity state. Use LineOfSight to check if the player is in sight. If not - pick a random item in range and find path to it.

    An example of logic:

    Initially the entity is in "idle" state.
    
    On "idle" timer: 
     -> Check if the player is in LOS. If true, find path to it, set state to "chase"
     -> Else : Pick a random item, find path to it, set state to "patrol"
    
    On Path found : move along path
    
    On Failed to find Path : set state to "idle" and start "idle" timer
    
    On Pathfinder arrive and state="patrol" : set state to "idle" and start "idle" timer
    
    If state="chase"
    Every 1 second : 
     -> Check if the player is in the attack range. If true, then stop and attack
     -> Else: check if the player is in chasing range. If true, find new path to the player
     -> Else: set state to "idle" and start "idle" timer
    
    If state="patrol"
    Every 1 second :
     -> Check if the item still exists. If not - set state to "idle" and start "idle" timer
    
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)