Coder Social home page Coder Social logo

aillieo / unitylos2d Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 3.0 1.66 MB

A simple Line of Sight (LOS) implementation with Unity physics ray casting system

License: MIT License

C# 90.84% ShaderLab 9.16%
unity los sight stealth stealth-game line-of-sight raycast 2d

unitylos2d's Introduction

Unity LOS 2D

A very simple Line of Sight (LOS) implementation with Unity physics ray casting system, including the following features:

  1. LOS related events

Register callbacks for static events in LOSManager. The available events are OnEnter and OnExit, which are invoked when a LOSTarget enters or exits the line of sight of one LOSSource, and instances of both the LOSSource and LOSTarget are sent to the listeners:

LOSManager.OnEnter += (source, target) =>
{
    Debug.Log($"{target.name} enters the sight of {source.name}");
};
  1. Sector shaped mesh generation

LOSMesh is for sector-shaped mesh generation, with some configurations:

image

'Associated LOSSource' : read angle and radius parameters from the given LOSSource

'Resolution' : the resolution for the sector

'Default FOV' : the angle of the sector if no LOSSource associated

'Default Max Dist' : the radius of the sector if no LOSSource associated

'Draw Simple Sector' : turn off target and obstacle detection, only draw sectors

'Draw Hidden' : draw the area blocked by obstacles

'Draw Sight' : draw the bright area that is not blocked by any obstacles

'Fill UV' : generate a mesh with uv

'Auto Regenerate' : regenerate mesh every frame

  1. Shader and texture tools for sector-shaped mesh

Shader: use sector-specific textures which supports border settings

Texture tool: convert a 90-degree sector image from Cartesian to the polar coordinate system to better support different radii and angles by setting borders. Right-click on the original texture and select "C2P".

image

Sample case:

The sample scene contains a composite example.

image

Usage

Clone this repository and copy it to your project folder, or add https://github.com/aillieo/UnityLOS2D.git#upm as a dependency in the Package Manager window.

unitylos2d's People

Contributors

aillieo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.