Renvix Assets

Vision Source

Something that sees: a player, a guard, a security camera, an RTS unit. Every update it computes the area visible from its position, clipped by the colliders around it. All other components work from this result.

full Vision Source Inspector in 2D mode with all sections unfolded.

Settings

Mode

The tabs at the top: 2D, 3D or 2D Isometric. See Modes.

In 2D Isometric mode two more settings appear:

SettingDescription
Isometric GridThe Grid of your isometric tilemap. Its Cell Size sets the proportions
Tile Size (W × H)Used when no grid is assigned: width and height of one tile on screen, the same numbers as the Grid's Cell Size. Default 1 × 0.5

View

SettingDefaultDescription
Range6How far the source sees, in world units. In isometric mode measured on the ground
Field of View (°)90Full opening angle. 360 sees in every direction
Looks AlongUp2D and isometric: which local axis of the object is the look direction (Up, Right, Down, Left). In 3D the object's forward axis is always used

Obstacles

SettingDefaultDescription
Blocked ByEverything except CharactersColliders on these layers block the view. Nothing makes a revealer without line of sight
Triggers BlockOffWhether trigger colliders block the view too
Own BodyAutoColliders on this object and its children never block this source. Empty = found automatically; the Inspector shows which object was found

More in Obstacles.

Team & Fog

SettingDefaultDescription
Team0The Fog Of War and Fog Hiders of this team are revealed by this source. See Teams
Fog Reveal1How much this source clears the fog: 1 = fully, lower = a dim half-light, for example for "sensing" what is near
Reveal At Edge1Reveal strength at the far edge relative to the center. Lower values fade out like a flashlight beam

Fog Reveal and Reveal At Edge change only the fog picture. What the source sees for AI and Fog Hiders is not affected.

two sources side by side, one with Reveal At Edge 1 (evenly clear area) and one with 0.2.

Performance

Folded by default.

SettingDefaultDescription
Edge Step (°)4Largest angle between rays along the far, rounded edge of the view. Smaller is rounder but costs more. Walls are always exact
Update Every (s)0Seconds between updates. 0 = every frame. See Updates and Quality

Buttons

Below the settings, while they are missing:

Runtime

In Play mode: the number of points in the outline of the visible area, and whether the last update was recomputed or reused because nothing moved.

Scripting

Namespace Renvix.VisionFog.

MemberDescription
bool CanSee(Vector3 worldPoint)True if the point was visible in the latest update. In 2D a Vector2 works too
bool CanSee(Vector3 worldPoint, ReadOnlySpan<int> ignoredColliderIds)The same, but colliders with these instance ids do not block
void ForceUpdate()Recomputes right now instead of waiting for the next update
event Action<VisionSource> UpdatedRaised after the visible area has been recomputed
bool HasResultTrue once the visible area has been computed at least once
int VersionIncreases whenever the visible area changes. Compare it with a stored value to detect changes
bool LastUpdateChangedFalse if the latest update reused the previous result
NativeArray<float2>.ReadOnly BoundaryOutline of the visible area in plane coordinates. Valid until the next update
VisionShape ShapePosition, range and angles used for the latest update, in plane coordinates
float EyeHeightHeight of the eyes at the latest update
float2 ToPlane(Vector3) / Vector3 ToWorld(float2, float)Converts between world positions and plane coordinates
Transform BodyThe body whose colliders are ignored, set or found automatically

The settings are available as properties: Plane, Radius, FieldOfView, Team, ObstacleLayers, FogRevealStrength, FogRevealAtEdge, UpdateInterval, IsometricGrid, IsometricTileSize.

Example: check a point

using Renvix.VisionFog;
using UnityEngine;

public class Turret : MonoBehaviour
{
    [SerializeField] VisionSource eyes;
    [SerializeField] Transform player;

    void Update()
    {
        if (eyes.CanSee(player.position))
            Fire();
    }

    void Fire() { /* ... */ }
}

If the point is inside a collider that is on the source's Blocked By layers, for example the center of the player's own collider, the collider itself hides the point. Exclude the characters' layer from Blocked By, use the overload with ignored collider ids, or use Vision Target and Vision Perception, which handle this for you.

Example: change the view at runtime

// A flashlight that narrows and reaches further while aiming.
source.FieldOfView = aiming ? 30f : 70f;
source.Radius = aiming ? 12f : 7f;