Home

Awesome

Logo openupm

Utility components for working with Raycasts using GameObjects

What is this

This library wraps Physics.XCast and Physics.OverlapX methods into MonoBehavior, and acts like a configurable sensor. With that, you can write logic that is less focused on ray casting logic, and more on reaction when ray hit something.

Features

Usage

public class CharacterObject : MonoBehaviour
{
    public CastSensor groundSensor;

    public void Update()
    {
        groundSensor.UpdateSensor();
        
        if (groundSensor.HasHit)
        {
            var normal = groundSensor.RayHit.normal;
            // ground movement logic
        }
        else
        {
            // airborn movement logic
        }
    }
}

Parameters

Sensor parameters

Nearly all of sensor parameters are actually Cast/Overlap method parameters, so i think if you need documentation for those, you can easily read detailed info in Unity Documentation. However, there is unique parameters:

Gizmo

Each sensor has detailed gizmo, to aid sensor configuration and allow quick visualization of current sensor behavior

Gizmo is visible only on selected game objects for peformance reasons Gizmo

Colors:

Architecture

This library is designed to allow faster Cast/Overlap iteration cycles, and give ability to easily swap between sensor types without code modification.

Class Diagram

Ray/Capsule casts are absent because they are SphereCast's special cases. If Radius = 0, Ray cast is used for detection, if Width > 0, Capsule cast is used. Similar logic applies to overlap sensors.

Every inheritance level has logic that allows to work with results independently of sensor type. So, if you just need to check for object prescence, you can use base class - PhysicsSensor just to get basic information about hit (Is detected something, Collider of detected object). With that, you can assign any sensor to that property, and if you need to change from BoxOverlap to SphereCast, you dont even need to modify your sources, you can just swap your sensor.

Sensor is not updated automatically, you need to call UpdateSensor() for that. Here is reasons:

Requirements

At least Unity 2018.1 or higher. 2019.1 is required for overriding PhysicsScene

Installation

Otherwise, you can just copy files from Assets/Scripts/Runtime to your project.

Changelog