How do I get Line of Sight to activate/deactivate on my player, and return to previous actions?

0 favourites
  • 7 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • 2d platformer, and I have a patrolling enemy (bee). I have has his patrol event set properly, and it works:

    (Bee Patrol Group, Line 9 - see pic below))

    bee travels to the left, collides with with invisible wall, mirrors, travels to the right, collides with wall, repeat.

    I want the bee to see the player, change animation and then move toward the player slightly faster (this is where I set the Move To event). I want the enemy facing to be toward the player, according to player.X position (lines 16 and 17 in pic below), however, I want the original behavior to be followed until the enemy sees the player, OR, when the player moves out of range, I want the enemy behavior to return to its default patrol.

    The first patrol group (Bee Patrol) works as intended - the enemy changes directions, and all is fine. However, when I activate the Bee_los group, the enemy does not change facing when hitting my invisible wall (which should trigger him to mirror and begin traveling to the right). The animation changes work fine.

    Attached is a screenshot of my event sheet, and a link to the game file. The faulty group (Bee_los) is deactivated, so you can see the game work normally before you get into the troubles.

    The player is set just to the left of the bee enemy, so upon initializing, you can sit in place and watch the bee hit the wall, and then mirror and patrol to the right. In the Enemy Behavior event sheet, activate the "Bee_los" group, initialize, and you will see the bee does not change direction.

    https://drive.google.com/file/d/1enUBFVRMzzz8FKQczdr2-k8mgjyzEaZQ/view?usp=sharing

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's because your events for mirrored in the LOS group are true even if the bee does not have LOS. You need to put those events as a sub event under the 'bee has LOS' event so it only forces the facing towards the player when the bee can see the player.

  • I set the direction events as subevents (Pic #1), but I will go ahead and apologize - this wording is confusing me.

    However, it produces some interesting results - close to what I am looking for, but not quite. Under the event sheet picture, I will show some example pictures of what I mean.

    Pic #1 - Sub Events

    For instance, when I stay away, the enemy behavior is fine. When I approach, the enemy comes at me, but he starts to "fly" upward, for some reason.

    Pic:

    Or maybe it is how I set up his behavior, but when I leave his LoS, his normal patrol pattern is broken. Is there a better way to set up his patrol behavior?

  • It will fly up because you have it set to MoveTo the player so there are no real restrictions. You can try forcing its Y position if you want to keep it at one level. To return to its patrol behaviour you'll have to add more logic to make it return to a certain location since it can escape the boundaries when it has LOS.

  • Any suggestions on how or what I might do to achieve that? I tried pathfinding (to much frustration), but that does not solve my problem of telling the bee "when you see the player: attack; when you do not see the player, or if the player leaves your line of sight, return to doing what you were doing, in the spot you were doing it".

  • Since you gave a lot of info I worked on the file for you, and added a status variable you can use to track what the bee is doing. You will notice this also takes out the need to deactivate groups because it now relies on the status of the bee.

    dropbox.com/scl/fi/wsttb3wgqe2vd8q7y54wr/Percival_edited.c3p

  • Oh wow, this is perfect! I have not tried (even thought of) states, much less did I expect you to do anything.

    THANK YOU!

    I admit, I would never have thought of this, either, so thank you for letting me see this code. This alone helps me with nearly every other enemy idea I have for the game.

    Thank you again!

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