How Do I Capture A Player's Last Known Location

0 favourites
  • 4 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • I am trying to make enemies ping a player's location every few seconds if they are not in line of sight and move toward that location. If they are in line of sight, chase the player until they lose sight again. I've created some instance variables that reference player.x and player.y thinking that would capture those numbers at the time the enemy is created or loses sight... but it seems to instead just reference the ongoing variable of player.x and player.y.

    Does anyone know of a better way to do this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think the problem is with "Wait 2 seconds" action. You should never use Wait in events which run on every tick. This creates hundreds of delayed threads for each enemy. And even if this enemy gets LOS to the player, those delayed threads continue firing..

    Add a "state" instance variable to enemies and use Timer behavior instead of the wait.

    When enemy is in "chase" state and no longer has LOS to the player, switch to "patrol" state and start a timer for 2s. In the timer event find a path to last known location.

    When enemy is in "patrol" state and gets LOS, stop the timer and switch to "chase" state.

  • So I think I have this working more or less the way I was searching for.

    The solution I came to adapted dop's advice with the states and and idea I had about dropping/replacing a marker every x seconds at the player's location and having the enemies move toward that. The enemies spawn in an "active" state and move toward the marker. Then if they see the player, they move toward them constantly and the marker's position constantly gets updated to the player's location. If they drop LOS, they go into a "searching" state and move toward the marker. I'll drop a screenshot of the event sheet in case anyone has a similar issue later.

    Thanks again dop!

  • "Else" event will not work correctly with multiple enemies. Instead of Else use "Enemy has NO LOS to player" condition.

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