Having trouble with Line of Sight

0 favourites
  • 10 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • I want to make a condition so that if an object doesn't have Line of Sight to ANY "enemy" objects, then it does something.

    The code i tried was:

    If Player does not have LoS to enemy object -- do something

    But the player could have LoS to 99 enemies, but no LoS to 1 of them, and the code still activates.

    I feel like this should be very simple but I can't figure out how to get around it.

    Am I missing something?

    Thanks for any help

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is there a Family "Enemies"?

    I think you can do:

    Object | Has Line of Sight to "Enemies" (Right click -> Invert) : Do something.

  • Is there a Family "Enemies"?

    I think you can do:

    Object | Has Line of Sight to "Enemies" (Right click -> Invert) : Do something.

    Hey thanks for the response.

    I'm trying to make it so that if there are no enemies at all in the player's line of sight, then it does something.

    "Object | Has Line of Sight to "Enemies" (Right click -> Invert) : Do something."

    When I do this, it will still work when it has no LoS of any enemies, but it will also activate if it has no LoS of one enemy and does have LoS of another enemy.

    My current idea is to set a value to the number of enemies not in LoS, and then compare it to the total number of enemies, and if they are the same, do the thing.

    But I will have to do this with multiple different objects and I already have a lot of values and was hoping i would not have to add a bunch more

  • Maybe a for loop ( for each enemy ) and has no line of sight as a sub event in there

  • No this doesn't work either.

    Even if the player has LoS to an enemy, it still technically also doesn't have LoS to a different enemy, and so the code will activate anyway.

  • Try this:

    If player has LoS to Enemies -> (no actions here)

    Else -> Do something here

    This event may look like the same as "Player NOT had LoS" condition, but in fact it works differently.

  • Ok I think I get the difference here.

    This definitely works thanks a lot for the help!

  • Try this:

    If player has LoS to Enemies -> (no actions here)

    Else -> Do something here

    This event may look like the same as "Player NOT had LoS" condition, but in fact it works differently.

    Sorry I just realized an issue.

    What if I need to add other conditions? Such as multiple values being certain numbers?

    Again I could just do:

    If player has LoS to Enemies -> (no actions here)

    Else -> Set value "NoLOS" to 1

    And then just use the "NoLOS" value instead of the LoS function

    But this would again mean having to add multiple values for different objects/scenarios. Which isn't the end of the world at all but I was just hoping there would be a more simple solution.

  • Why don't you create a sub-event under the Else and put those additional conditions there?

  • Hey thanks so much again for the help.

    I didn't know that could be done, I've never used the else function before, but it works perfectly.

    I totally forgot about the manual and if I run into any more issues I'll read that before asking here.

    You've been a great help thanks again for the patience and assistence

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