How do I use line of sight for platformer enemies?

0 favourites
  • 11 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • Hi,

    I have a stationary enemy that I want to only shoot straight ahead when the player is in it's line of sight. But I only want the enemy to shoot what is in front of it (depending on which direction it is facing). So if the enemy is facing left, it will only shoot to the right, and if facing right, will only shoot to the left.

    I tried using this event but the enemies don't shoot when the player is in front of them.

    Any help is appreciated.

  • From this pic I can see only one possible problem.

    In this picture your eye will only shoot if wizard is visible exactly at the end of every second second. (no pun intended)

    If you want to shoot at the player moment it sees him/her you should, instead of "Every 2.0 seconds" put variable inside eye that will act as a timer from which you will subtract dt, and then condition will be "if Enemy_Eye.variableName < 0", and you will need action "set Enemy_Eye.variableName to 2" (put together with spawn action)

    EDIT:

    also check "range" and "cone of view" of Line of sight behavior.

  • Thanks for the reply.

    What's weird is that if I just have the player stand in what should be the LOS, the Eye won't shoot. I have changed the cone of view between 180 and 360, neither seem to alter the behavior, and range is default 1000px for now. Something's just not right.

    I'll definitely implement a cool down timer like you mentioned.

  • Maybe something else is the problem. Can you give me capx?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sure, I have a capx here:

    https://

    dl.dropboxusercontent.com

    /u/53823971/temp_images/Platform_LOS.capx

    (Had to format the link weird because I don't have enough reputation to post links.)

  • Have not used LOS before, so I played with it now.

    It seems that cone of view must be positioned in front of the object, which is to the right, so you will have rotate object by 180 to make it look left.

    (for all objects default angle 0 is to the left, so they should be drawn facing left, and then mirrored, which LOS takes into account, it seems)

    Also another limitation seems to be that entire object must be inside cone of view.

    So my advice would be to set Cone of View larger then needed and then set another condition which will compare player angle to eye angle. (you can put 360 if you do not have many such instances which will eat your hardware)

    In example in the picture, cone of view is set to 360, and then another condition (last in line 6) limits it to 30 degrees behind enemy.

    Also one more problem in your example is that you have 2 Enemies, and you text field will be overwritten by enemy who cannot see you, so it is enough that only one enemy cannot see you it will say "Player is Undetected"

  • Thanks Razor for looking into this. I can't seem to find how to create that System condition posted above.

    I have been messing with LOS and just can't get it to work like I expected it. I figured I could have a bunch of stationary enemies with this behavior, and have them shoot at the player when he is visible, but it just doesn't work like I'm expecting it to.

    I came across this tutorial which I think will help me (or anyone with this issue):

    https://www.scirra.com/tutorials/1320/p ... enemies-ai

    Instead of relying on line of sight, just calculate the distance between the player an enemy for its range.

  • I am having that same problem. Any clues?

  • Never figured it out :/ I asked ArcadeEd (who does C2 Twitch streams) and he plans to cover it for me sometime soon.

  • I found out what might be the problem. At least what was causing my Line of Sight not to work with my platformer game. If you, like me, use the character pivot set to bottom it is causing the line of sight to be buried in the ground. Once I changed the pivot a few pixels up it worked.

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