• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

### #Actualnonoptimalrobot

Posted 21 August 2013 - 08:34 PM

Even if you didn't have layers (height) and the game took place in a single plane you would still have this problem.  It is essentially one of occlusion.  The player can be obscured from an AI's view by geometry in the horizontal plane.  To see what I mean just look at your diagram as if it was a top down representation and the different levels were walls.  I know, it's a drag.

The "easy" way to do this is as Zipster suggested but you'll have to cast rays in 3 dimensions and impart your tiles with height information.  Fortunately tracing rays though a regular grid can be done efficiently.  You can mitigate the cost by not casting all your rays each frame; human AIs modeling vision rarely need to be updated every frame.

A hacky way to do the same would be to buffer a no-visibility zone around the border of elevated levels and scale the extent of the zone based on the distance an AI is to the edge.  Each AI would need to track it's own scaling factor.  You can work out the amount of scale with some simple trig.  Even if you do this it's a limited solution that doesn't solve any of your other visibility problems.

  Here's some brief math to help you out with that...

HeightOfAI / DistanceToEdge = HeightOfLayer / OcclusionDistance

OcclusionDistance = HeightOfLayer * DistanceToEdge / HeightOfAI

### #1nonoptimalrobot

Posted 21 August 2013 - 07:40 PM

Even if you didn't have layers (height) and the game took place in a single plane you would still have this problem.  It is essentially one of occlusion.  The player can be obscured from an AI's view by geometry in the horizontal plane.  To see what I mean just look at your diagram as if it was a top down representation and the different levels were walls.  I know, it's a drag.

The "easy" way to do this is as Zipster suggested but you'll have to cast rays in 3 dimensions and impart your tiles with height information.  Fortunately tracing rays though a regular grid can be done efficiently.  You can mitigate the cost by not casting all your rays each frame; human AIs modeling vision rarely need to be updated every frame.

A hacky way to do the same would be to buffer a no-visibility zone around the border of elevated levels and scale the extent of the zone based on the distance an AI is to the edge.  Each AI would need to track it's own scaling factor.  You can work out the amount of scale with some simple trig.  Even if you do this it's a limited solution that doesn't solve any of your other visibility problems.

PARTNERS