Search Unity

Cone of Sight Visualization

Discussion in 'Scripting' started by Marrt, Feb 13, 2012.

  1. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    Hi,

    i want to achieve a cone of sight visualization for a top down shooter,
    a concept picture:
    $TopDownConcept.JPG

    should behave like the cone in Nox (westwood, year 2000)
    $los.jpg

    i cant find how to implement this feature but its crucial to the gameplay i am aiming at.

    -Its mainly what a ~300° radiation angle light source would do (except the not-rendering parts of out of sight enemy ships)
    -all the action happens in one Z-plane, so the shadow only needs to be 2 dimensional
    -i would be satisfied if the not-rendering parts wont work and i would have to use a deep black shadow to achieve sight blocking

    is that the only way?:
    http://unitycoder.com/blog/2012/01/04/fake-realtime-raycast-shadows-unity3d/

    likewise problem:
    http://forum.unity3d.com/threads/91630-How-to-Render-a-True-Cone-of-Sight

    ____________________________

    UPDATE:

    Done Basics! Now thats what i expect from TopDownShooter concerning Movement and Aiming:

    $SpaceNox0.1.JPG

    DOWNLOAD-WebPlayer: (OUTDATED)
    View attachment $SpaceNox.7z

    Try this instead:
    http://marrt.elementfx.com/

    W A S D: Movement
    SPACE: Movement Toggle between Arcade/Referential
    RightMB: FreeCursor+Splitscreen on Distance, Awsome, TRY IT!
    ScrollWheel: Zoom

    the camera is a bit Jumpy but who cares yet...
    next Step: use mgears VisibilityMesh to Hide/show enemies... ThankYou mgear :rolleyes:, never expected to get that far
     
    Last edited: Apr 23, 2012
  2. runonthespot

    runonthespot

    Joined:
    Sep 29, 2010
    Posts:
    305
    @Quickfingerz in his recent speech for #Luug, discussing Covert (a runner up in the Flash in a Flash Unity competition) did a brute-force method, by literally raycasting 90 rays over the arc (not a cone really) and joining the dots to draw a procedural poly. It's ugly but it works. Where multiple cameras were required, he had to reduce the number of rays to keep it scaling, so may not be suitable for large numbers of enemies.

    I believe there is a procedural poly maker on the UnifyCommunity Unity Wiki.

    The other option that might work for you is to place a spotlight on the character's head, and assuming you have Unity shadows on, you should achieve a similar effect.

    Worth keeping in mind that this is just for the actual visuals. The actual detection can just use a single normal raycast between enemy and player or vice versa to determine if they are actually visible or not.
     
    Last edited: Feb 13, 2012
  3. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    -Sounds good, isnt that similar to this raycast approach?
    http://unitycoder.com/blog/2012/01/04/fake-realtime-raycast-shadows-unity3d/

    -Spotlight can only have 180° as far as i have seen in the editor, i would need a 270° sphere at least... and realtime shadows are still a pro feature

    I also came across this page, looks promising but i cant figure out if its cheap in performance...
    http://www.catalinzima.com/2010/07/my-technique-for-the-shader-based-dynamic-2d-shadows/

    i admit we are still within the feasability study of this game project, checking if we can implement all features using unity(free :D), this is the last issue before we can start.
     
  4. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    There must be a simpler way, when i raycast a number of rays to far away edges it results in jumpy shadowarcs if i am not using 1000 rays:
    http://unitycoder.com/upload/demos/mShadowRayScan1/

    maybe i can reduce the problem.... only raycasting to the edges of the polygons should be enough, also i only need to cast to the edges of the visible geometry... basically i need to solve this with multiple viewing points (share field of sight with allies):

    http://en.wikipedia.org/wiki/Visibility_polygon

    but when i use round obstacles with lot of edges it will slow down big time i guess...
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,444
    theres new test version,
    http://unitycoder.com/blog/2012/02/15/raycast-realtime-visibility-2-0/
    (its much faster, as it doesnt triangulate or make uv's in every frame, like the old one..)

    some interesting links,

    Visibility Algorithm Overview
    http://groups.csail.mit.edu/graphics/classes/6.838/S98/meetings/m23/alglist.html

    Portals and Mirrors: Simple, Fast Evaluation of Potentially Visible Sets
    http://www.cs.virginia.edu/~luebke/publications/portals.html

    A simple, fast, integer-based line-of-sight algorithm
    http://karoshi.auic.es/index.php?topic=1085.0
     
  6. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    wow, thanks mgear, looks good.
    -does the pseudopolygon always have to have a tint? i dont want to distort the colors of the underneath textures. maybe i can add a depth shader to the created mesh to mask things out - like the one i use for dynamic splitscreen... then it should work like a cutout-the-visible-area-polygon. then they would be overlapable as well...
    ____
    yesterday i started programming until late night (appeared late in office today though). Unity is awsome, i juggled some scripts around and after 6 hours things are already moving and doing what i want :D.

    i even managed to get non rectangular viewports working.

    the next biggy is this algorithm... but im faithful
    i want to be able to share field of view with allies, its then like a multipoint visibility polygon problem, hopefully this doesnt mess up every approach

    man, maybe i can even add some kind of terrain destruction using voxelform2.0
     
    Last edited: Feb 15, 2012
  7. ivkoni

    ivkoni

    Joined:
    Jan 26, 2009
    Posts:
    978
  8. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
  9. Sprak

    Sprak

    Joined:
    May 20, 2008
    Posts:
    28
    That looks fantastic. Care to share the source?
     
  10. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    For a top down shooter, you dont need a cone but a 2d triangle or semicircle sort of view.

     
  11. okletshavesomefun

    okletshavesomefun

    Joined:
    Jul 30, 2015
    Posts:
    5
    wickedwaring likes this.