How do I find no-LoS position in range

0 favourites
  • 7 posts
From the Asset Store
Graphic - Alien UFO
$1.80 USD
40% off
Vector illustration of a UFO with an alien in three different positions.
  • Hi everyone,

    Can someone suggest an efficient approach to finding a random spot in a range around my character that has no Line of sight to its current position?

    All I can think of is looping through positions around dedicated objects, but I'd like to be free of that object constraint

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I would do this:

    RADIUS=   [minimum distance from the character]
    r=int(random(360))
    For x=r to r+360
       xFound=character.X+RADIUS*cos(loopindex)
       yFound=character.Y+RADIUS*sin(loopindex)
    
       Character has NO LoS to (xFound, yFound)
            Stop loop
    [/code:2a553ctr]
    
    This will give you a random point at RADIUS distance. (a random line out of sight) 
    Then, if you wish, you can move this point further from the character along this line.
  • ObjectA has los to ObjectB

    ObjectB pick closest to ObjectA

    ->ObjectA set direction to angle(ObjectA.x,ObjectA,y,ObjectB.x,ObjectB.y)-180

    If you don't want it to appear like it's pushing itself away you could use an invisible dummy object, and then move to the dummy position when it doesn't have los.

    Not that it would guarantee a non los position for every circumstance. It could, in theory, just go forever.

    But it is fun to watch.

  • newt

    Is there ObjectB?

    I thought facecrime wanted to find a random point on the layout not visible to character. Probably to spawn an enemy there or something like that. Maybe I misunderstood the question.

  • Depends on the game type I guess.

    Line of Sight kind of implies it.

    My method might not work with walls in a hide-n-seek scenario.

    Snakes on a plane?

    Good to go.

    Sorta.

  • dop2000

    newt

    Thanks for the suggestions!

    My hope was to find a solution without raycast loops, assuming those to be expensive, at least in 3d engines, but couldn't think of anything. (Should have phrased that better in the question)

    I want to find a potential hiding spot and I don't want to tie myself do a specific object.

    I'll just give it a spin and look at the actual impact, thanks guys

  • I tried it before posting - a loop with 360 LoS checks on every tick, I was getting steady 60FPS.

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