Completely Bewildering Line of Sight Stuff

This forum is currently in read-only mode.
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • So, I'm trying to do some simple stealth gameplay using the Line of Sight behavior, but it... um... doesn't seem to be working very well.

    Every guard has an 'Aware' private variable that defines whether they are patrolling (aware at 0) or attacking the player (aware at 1). The code involved is pretty simple (at least, I hope):

    Enemy: Has player in line of sight. >> Enemy: Set Aware to 1
    Else: Enemy: Set Aware to 0[/code:22xxd6pw]
    
    The code for what to do when an enemy [i]does[/i] see the player is more complex:
    
    [code:22xxd6pw]Enemy: Value 'Aware' Equal to 1 >> Enemy: Move to Player
    Sub-Event:
    Enemy: overlaps Player at offset 20,0
    OR
    Enemy: overlaps Player at offset -20,0
    OR
    Enemy: overlaps Player at offset 0,20
    OR
    Enemy: overlaps Player at offset 0,-20
    Sub-Event:
    Enemy: Value 'Current Cooldown' Less or equal 0 >> Enemy: Set 'Attacking to 1
    

    Enemy: Set 'Current Cooldown to Enemy.Value('Attack Cooldown')[/code:22xxd6pw]

    I did try to put the "Move to Player" RTS behavior command in an else statement for the is-the-enemy-adjacent-to-the-player subevent, but this caused all enemies to attack the player, regardless of whether or not they were aware of him.

    Even in the current form, however, the enemy behavior is absolutely bewildering. Enemy line-of-sight appears to linger after death, and stepping into the line of sight of a destroyed enemy sometimes crashes the game. Killing any two of the three guards crashes the game. One enemy informs me that he is completely aware of the player, but nevertheless simply stands still. He'll attack the player if he moves in close, but he refuses to respond to commands (even in the above scenario, where I placed everything in an else sub-event, only the enemies who couldn't see the player attacked him - this one stayed put).

    Am I just running into a bug? Or is there anything I can do to alleviate this situation?

  • http://sourceforge.net/apps/mediawiki/construct/index.php?title=Families

    Its all about picking.

    If you have multiple's of the same object then tell the object to do something, all will do it.

    You need a way to select a single object from a group of objects.

    Families provide that.... as long as that single object is picked.

  • Well, that's the thing. I can't figure out how to pick one single object. The game seems determined to pick objects that don't exist (this seems to be what causes the crashes) or to skip over objects for no reason (the one enemy who just stands still).

  • I attempted to recreate the problem with the details you provided. Don't use the OR condition. While OR works well enough in most cases, it's what is causing the crashes in your case. Not sure about the other problems. More details are needed, or a cap would be nice.

  • I attempted to recreate the problem with the details you provided. Don't use the OR condition. While OR works well enough in most cases, it's what is causing the crashes in your case. Not sure about the other problems. More details are needed, or a cap would be nice.

    This seems to have partially resolved the problem, actually. Is there any chance you could explain what it is that prevents the OR condition from working in this situation?

    Still pressing on with this, the ghost-line-of-sight bug still seems to be at work.

    I've narrowed down one bug pretty far. The error appears to be in this section of code:

    (ignore the sub-event for the player-is-in-line-of-sight event, it's for a different system and has been toggled off)

    With the code as shown (all other code that refers to the Guard object or any of the families it's in has been toggled off or is in a disabled group, with the exception of a single event to enable me to destroy Enemies by clicking on them, for testing purposes), of the three guards, precisely one will cause the game to crash if he is killed and I walk into his former line of sight. There is no difference between this guard and the other guards, besides a handful of private variables related to currently disabled AI patrol routes. The bug is consistent - if the guard is dead, and the player stands in a place that would have been in the guard's line of sight at the time of his destruction, the game will crash.

    There is also a "boss" sprite in the layout that is in the Enemy family, but is not the same object as the guards. Destroying this boss sprite and standing in its line of sight does not crash the game.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Exploring the problem further, I think the problem is that, for whatever reason, Construct insists on always running these tests for the oldest object in a Family, regardless of whether that object exists or not. This is kind of inconvenient, to say the least. Is there any obvious solution I'm missing here?

  • Might try inverting "has los" instead of having the else.

  • Tried it. The bug is still there.

  • In fact, I just tried without the ELSE event at all, and the bug was still there. The bug is definitely caused by

    Enemy: 29 Has LOS to Player 0 
    

    EnemySet 'Aware' to 1

    [/code:3kij5mre]

    And that event alone.

  • Aha!

    After some additional experimentation, I was able to finally remove the bug - by toggling off the event setting line of sight for enemies to be blocked by walls!

    I have no idea why this should be the case, but it appears that the line of sight bug is somehow dependent on this event as well:

    System: 1Start of layout
    

    EnemyAdd LOS obstacle Wall 0

    [/code:1opfyid9]

    As the bug occurs with only these two events, it probably doesn't involve any others.

  • For the sake of completeness, I've uploaded a bug report, including what additional information I've been able to discern and a .cap: http://sourceforge.net/tracker/?func=de ... id=1003219

  • i think i figured this out

    I was searching for family crash on the bug tracker

    and your problem reminded me of mine

    try replacing the events so it doesn't use families

    then remove the enemy family altogether

    it stopped crashing for me

    my own crash on my own project had to do with sprite overlapping checks, but removing families from the project fixed the crash. I don't think it has to do with line of sight at all

  • So, basically, families are just useless?

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