Search Unity

Checking if a point is inside a Collider

Discussion in 'Entity Component System' started by demozbox, Nov 18, 2020.

  1. demozbox

    demozbox

    Joined:
    Nov 26, 2014
    Posts:
    83
    Hello. I am following Unity docs and want to Checking if a point is inside a Collider.
    There is an example code:
    Code (CSharp):
    1. public class Example : SystemBase
    2. {
    3.    protected override void OnUpdate()
    4.    {
    5.        // Fetch the PhysicsWorld through the PhysicsWorldSystem
    6.        var worldSystem = World.GetExistingSystem<PhysicsWorldSystem>();
    7.        var physicsWorld = worldSystem.PhysicsWorld;
    8.  
    9.        // Create an input object to define the point data
    10.        var point = new OverlapPointInput()
    11.        {
    12.            Position = float2.zero,
    13.            Filter = CollisionFilter.Default
    14.        };
    15.  
    16.        // Check if any of the colliders in the world are overlapping the point
    17.        if (physicsWorld.OverlapPoint(point))
    18.        {
    19.            // Hit!
    20.        }
    21.    }
    22. }
    23.  
    But what is the PhysicsWorldSystem, OverlapPointInput and CollisionFilter? Its highlightes with red line in VisualStudio and Alt+Enter doestn give any suggestion.
     
  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992