Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Visual Script logo Manual

Overlap Capsule 3D#

Physics 3D / Overlap Capsule 3D

  • Can Read

  • Cannot Write

Description#

Returns all 3D colliders that overlap with a capsule

Parameters#

Name Description
Point 0 The center of the sphere at the start of the capsule
Point 1 The center of the sphere at the end of the capsule
Radius The radius of the capsule
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 Unity.Scripting.LifecycleManagement;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]

    [Title("Overlap Capsule 3D")]
    [Category("Physics 3D/Overlap Capsule")]

    [Description("Returns all 3D colliders that overlap with a capsule")]
    [Image(typeof(IconCapsuleOutline), ColorTheme.Type.Lime, typeof(BadgePhysics))]

    [Parameter("Point 0", "The center of the sphere at the start of the capsule")]
    [Parameter("Point 1", "The center of the sphere at the end of the capsule")]
    [Parameter("Radius", "The radius of the capsule")]
    [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", "Capsule", "Pill", "3D")]

    [Serializable]
    public class TypeCollectionGameObjectsPhysicsOverlapCapsule : TypeCollectionGameObjects
    {
        [NoAutoStaticsCleanup]
        private static readonly Color GIZMO = new Color(0f, 1f, 0f, 0.25f);

        [NoAutoStaticsCleanup]
        private static readonly Collider[] HitsBuffer = new Collider[128];

        [SerializeField] private GetVector3 m_Point0 = new GetVector3(new Vector3(0f, -1f, 0f));
        [SerializeField] private GetVector3 m_Point1 = new GetVector3(new Vector3(0f, 1f, 0f));
        [SerializeField] private GetNumber m_Radius = new GetNumber(1f);

        [SerializeField] private LayerMask m_LayerMask = Physics.DefaultRaycastLayers;
        [SerializeField] private GetBool m_UseTriggers = new GetBool(false);

        public override void Get(Args args, List<GameObject> values)
        {
            Vector3 point0 = this.m_Point0.Get(args);
            Vector3 point1 = this.m_Point1.Get(args);
            float radius = (float) this.m_Radius.Get(args);

            QueryTriggerInteraction triggerInteraction = this.m_UseTriggers.Get(args)
                ? QueryTriggerInteraction.Collide
                : QueryTriggerInteraction.Ignore;

            int numHits = Physics.OverlapCapsuleNonAlloc(
                point0,
                point1,
                radius,
                HitsBuffer,
                this.m_LayerMask,
                triggerInteraction
            );

            GizmosManager.Capsule3D(point0, point1, radius, GIZMO, GizmoMode.Outline, 0.25f);

            values.Clear();
            for (int i = 0; i < numHits; ++i)
            {
                Collider collider = HitsBuffer[i];
                if (collider != null) values.Add(collider.gameObject);
            }

            Array.Clear(HitsBuffer, 0, numHits);
        }

        public override string ToString()
        {
            return $"Overlap Capsule ({this.m_Point0}, {this.m_Point1}) radius {this.m_Radius}";
        }

        protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.