Overlap Point 2D#
Physics 2D / Overlap Point 2D
Can Read
Cannot Write
Description#
Returns all 2D colliders that overlap with a specific point
Parameters#
| Name | Description |
|---|---|
| Point | The coordinate point to check |
| Layer Mask | Filter to check objects only on specified layers |
| Use Triggers | Whether to check for Colliders marked as triggers or not |
Code#
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Overlap Point 2D")]
[Category("Physics 2D/Overlap Point")]
[Description("Returns all 2D colliders that overlap with a specific point")]
[Image(typeof(IconVector2), ColorTheme.Type.Lime, typeof(BadgePhysics))]
[Parameter("Point", "The coordinate point to check")]
[Parameter("Layer Mask", "Filter to check objects only on specified layers")]
[Parameter("Use Triggers", "Whether to check for Colliders marked as triggers or not")]
[Keywords("Inside", "Point", "Position", "Location")]
[Serializable]
public class TypeCollectionGameObjectsPhysics2DOverlapPoint : TypeCollectionGameObjects
{
private static readonly Color GIZMO = new Color(0f, 1f, 0f, 0.25f);
[SerializeField] private GetVector2 m_Point = new GetVector2();
[SerializeField] private LayerMask m_LayerMask = Physics2D.DefaultRaycastLayers;
[SerializeField] private GetBool m_UseTriggers = new GetBool(false);
public override void Get(Args args, List<GameObject> values)
{
Vector2 point = this.m_Point.Get(args);
List<Collider2D> colliders = ListPool<Collider2D>.Get();
int numColliders = Physics2D.OverlapPoint(
point,
new ContactFilter2D
{
useLayerMask = true,
layerMask = this.m_LayerMask,
useTriggers = this.m_UseTriggers.Get(args)
},
colliders
);
GizmosManager.Sphere(point, Quaternion.identity, 0.01f, GIZMO, GizmoMode.Outline, 0.25f);
values.Clear();
for (int i = 0; i < numColliders; ++i)
{
Collider2D collider = colliders[i];
if (collider != null) values.Add(collider.gameObject);
}
ListPool<Collider2D>.Release(colliders);
}
public override string ToString()
{
return $"Overlap Point at {this.m_Point}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}