Forum begins after the advertisement:
[Part 10] Issues with boss collider and diving attack
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 10] Issues with boss collider and diving attack
- This topic has 9 replies, 2 voices, and was last updated 1 day, 6 hours ago by
Nirvik Rajbhandari.
-
AuthorPosts
-
November 15, 2026 at 8:14 am #20144::
During the dive attack, the Boss clips through the ground. https://github.com/KingPloof393/Metroidvania-Prototype
November 15, 2026 at 11:00 am #20145::Hello Nirvik! Thank you for sharing your repository link. While I can’t open the GitHub project directly from here to inspect your scene files, we can definitely navigate through the pathways of your boss’s physics setup together and track down why this clipping is happening.
When an entity clips through the floor during a high-speed maneuver like a dive attack, it usually means the movement logic and Unity’s physics engine are stepping out of sync—almost like one is moving through a doorway before the other knows the door is closed.
Let’s methodically explore the possible culprits, starting from the code and moving into the Inspector settings.
Step 1: Tracing the Dive Movement Code
The most common reason a boss ignores the floor during a dive is how its position is being updated in the script. Let’s look at how your dive attack is written:
- Are you using
transform.positionorMoveTowards? If your dive code moves the boss by directly modifyingtransform.position(for example, usingVector2.MoveTowardsortransform.Translate), it is essentially teleporting the boss in small increments every frame. This completely bypasses Unity’s physics calculations, forcing the boss through solid colliders before a collision can be resolved. - The Physics Approach:
If the boss relies on a solid collider to stop at the ground, it’s usually best to move it using its
Rigidbody2D(such as settingrb.velocityor usingrb.MovePosition()) insideFixedUpdate(). - The Raycast / Ground-Check Approach:
If the tutorial’s architecture intentionally uses
transform.positionor a custom ground-check sensor (like aPhysics2D.RaycastorOverlapCircleat the boss’s feet) to tell the state machine “stop diving, we hit the floor,” then the bug likely lies in that sensor check failing to trigger in time.
Step 2: Checking for High-Speed “Tunneling”
If you are using
Rigidbody2Dvelocity, a very fast dive can cause the boss to be above the ground on one physics frame, and completely below it on the next—never actually intersecting the thin ground collider in between.- Select your Boss GameObject in the Inspector and find the Rigidbody2D component.
- Check the Collision Detection setting. By default, it is set to
Discrete. Change this toContinuous. This tells Unity to trace the entire path between frames so fast-moving objects can’t slip through thin floors.
Step 3: Inspecting the Colliders and Layers
Sometimes the dive state accidentally alters how the boss interacts with the world, or the colliders themselves aren’t configured to block each other.
- Trigger vs. Solid Colliders: Check the
Collider2Don both your Boss and your Ground. Make sure Is Trigger is unchecked on the primary colliders meant to keep the boss above ground. (Also check your animations or dive code to ensure you aren’t accidentally disabling the boss’s collider or turning it into a trigger when the dive begins!). - The Layer Collision Matrix: Go to
Edit > Project Settings > Physics 2Dand look at the matrix at the bottom. Find the Layer your Boss is on and the Layer your Ground is on, and ensure the checkbox where they intersect is ticked.
Where should we look next?
To help us zero in on the exact cause, could you copy and paste the snippet of code from your Boss script that handles the dive attack state (and any ground-checking logic attached to it) right here into the thread?
Once we can see how the dive movement is calculated, we’ll know right away which path to take to fix it!
November 15, 2026 at 3:51 pm #20146::Here is the boss’s groundcheck public bool Grounded() {
if (Physics2D.Raycast(groundCheckPoint.position, Vector2.down, groundCheckY, whatIsGround) || Physics2D.Raycast(groundCheckPoint.position + new Vector3(groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround) || Physics2D.Raycast(groundCheckPoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround)) { return true; } else { return false; } }November 15, 2026 at 3:52 pm #20147::Here is the boss’s dive funciton. override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { Boss.Instance.divingCollider.SetActive(true);
if(Boss.Instance.Grounded()) { Boss.Instance.divingCollider.SetActive(false); if(!callOnce) { Boss.Instance.DivingPillars(); animator.SetBool("Dive", false); Boss.Instance.ResetAllAttacks(); callOnce = true; } }}
November 15, 2026 at 4:45 pm #20148::Thank you for sharing those snippets, Nirvik! Seeing how the state machine and the raycasts connect gives us a great map of the first half of this mechanism.
Let’s examine what we have in front of us:
Grounded(): Your boss uses three downward raycasts originating fromgroundCheckPointto sense the floor on thewhatIsGroundlayer.OnStateUpdate(): While in this dive state, the boss turns on itsdivingColliderand waits every frame untilGrounded()returnstruebefore ending the dive, spawning the pillars, and resetting its attacks.
However, notice what is missing from this room of the labyrinth: there is no movement code inside
OnStateUpdate. This script checks if the boss has landed, and handles what happens after it lands, but something else is actually pushing the boss downward toward the floor.Let’s trace the pathways where that downward force or movement is coming from, and why it’s bypassing both your physical colliders and your
Grounded()raycasts.
Clue 1: Finding the Downward Movement
Where is the downward velocity or position change being applied? There are three likely places in a State Machine Behavior setup like this:
OnStateEnter()in this same Dive script (or the state right before it, like a “Jump” or “Dive_Prepare” state), where a downward velocity or gravity change might be applied toBoss.Instance.rb.- A method inside
Boss.cs(such as insideUpdate()orFixedUpdate()) that moves the boss when the dive attack is active. - The Animation Clip itself, if the dive animation is directly animating the Boss’s
Transform.position.yor root motion (which would force the boss through the floor regardless of physics).
Could you check
OnStateEnterin this script (or theBossscript itself) to see how the boss is actually propelled downward, and share that snippet?
Clue 2: The
divingCollidervs. The Main Body ColliderLook closely at the very first line of
OnStateUpdate:Boss.Instance.divingCollider.SetActive(true);In this tutorial series,
divingCollideris typically a child GameObject with a collider meant to damage the player during the dive. However, let’s check how your colliders are interacting:- Is the Boss’s main body collider being disabled during the dive? If an animation or script disables the Boss’s primary solid
BoxCollider2D/CapsuleCollider2Dwhen the dive starts, anddivingColliderhas Is Trigger checked (so it can deal damage to the player), then the boss has no solid collider left to physically stop it when it hits the floor! - If the boss has no solid collider active, it will fall straight through the floor. And if it falls fast enough, the short
groundCheckYraycasts might pass completely through a thin floor collider between two frames without ever registeringGrounded() == true!
Clue 3: Inspecting
groundCheckPointandwhatIsGroundSince your dive only stops when
Boss.Instance.Grounded()returnstrue, ifGrounded()fails to detect the floor, the boss will remain stuck in the dive state forever and keep plummeting.Let’s verify the sensor setup in the Unity Inspector on your Boss GameObject:
whatIsGroundLayerMask: Is the LayerMask dropdown on the Boss script set to your Ground layer? And is your floor GameObject actually assigned to that Ground layer?groundCheckYLength: What value do you have set forgroundCheckY? If this number is very small (like0.05or0.1), a fast-moving boss can easily skip past that tiny distance in a single frame. Try temporarily increasinggroundCheckYslightly (or checking thatgroundCheckPointis positioned right at the bottom edge of the boss’s feet).- Continuous Collision Detection: Select the Boss in the Inspector, find its Rigidbody2D, and set Collision Detection from
DiscretetoContinuous. This prevents the physics engine from letting the boss tunnel through the floor between frames.
Let us know what you find in those Inspector settings, and if you can share the
OnStateEntercode (or wherever the downward dive velocity is applied), we’ll have the final piece of the puzzle!November 15, 2026 at 10:38 pm #20149::%YAML 1.1 %TAG !u! tag:unity3d.com,2011: — !u!1 &315919253221015634 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 6060635570027466028}
- component: {fileID: 3356951505271205003} m_Layer: 6 m_Name: Diving Collider m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 0 — !u!4 &6060635570027466028 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 315919253221015634} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3427063659719920997} m_RootOrder: 6 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} — !u!58 &3356951505271205003 CircleCollider2D: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 315919253221015634} m_Enabled: 1 m_Density: 1 m_Material: {fileID: 0} m_IsTrigger: 1 m_UsedByEffector: 0 m_UsedByComposite: 0 m_Offset: {x: 0.121016026, y: 0.4671595} serializedVersion: 2 m_Radius: 3.7969635 — !u!1 &1868747825377609590 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 2524676789858584298}
- component: {fileID: 6971554679146191453}
- component: {fileID: 6843237794260753191}
- component: {fileID: 5751103914955507551} m_Layer: 0 m_Name: Boss Sprite m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 — !u!4 &2524676789858584298 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1868747825377609590} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 2, y: 2, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3427063659719920997} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} — !u!212 &6971554679146191453 SpriteRenderer: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1868747825377609590} m_Enabled: 1 m_CastShadows: 0 m_ReceiveShadows: 0 m_DynamicOccludee: 1 m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_RayTracingMode: 0 m_RayTraceProcedural: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials:
- {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} m_StaticBatchInfo: firstSubMesh: 0 subMeshCount: 0 m_StaticBatchRoot: {fileID: 0} m_ProbeAnchor: {fileID: 0} m_LightProbeVolumeOverride: {fileID: 0} m_ScaleInLightmap: 1 m_ReceiveGI: 1 m_PreserveUVs: 0 m_IgnoreNormalsForChartDetection: 0 m_ImportantGI: 0 m_StitchLightmapSeams: 1 m_SelectedEditorRenderState: 0 m_MinimumChartSize: 4 m_AutoUVMaxDistance: 0.5 m_AutoUVMaxAngle: 89 m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 m_Sprite: {fileID: -1673632557, guid: 252da50eb3b236e47b28177b6f40a123, type: 3} m_Color: {r: 0.39215687, g: 0.39215687, b: 0.39215687, a: 1} m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 m_Size: {x: 4.57, y: 5.29} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 — !u!95 &6843237794260753191 Animator: serializedVersion: 5 m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1868747825377609590} m_Enabled: 1 m_Avatar: {fileID: 0} m_Controller: {fileID: 9100000, guid: 58ebbb5cbe32f8141b518584e33d786d, type: 2} m_CullingMode: 0 m_UpdateMode: 0 m_ApplyRootMotion: 0 m_LinearVelocityBlending: 0 m_StabilizeFeet: 0 m_WarningMessage: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 — !u!114 &5751103914955507551 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1868747825377609590} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 24d2c235b8000f34480e9680bf86e1f5, type: 3} m_Name: m_EditorClassIdentifier: — !u!1 &2533921590850568867 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 4106419287293654058}
- component: {fileID: 3803985373559092970} m_Layer: 0 m_Name: Light 2D m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 — !u!4 &4106419287293654058 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2533921590850568867} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 1.3, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3427063659719920997} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} — !u!114 &3803985373559092970 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2533921590850568867} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 073797afb82c5a1438f328866b10b3f0, type: 3} m_Name: m_EditorClassIdentifier: m_ComponentVersion: 1 m_LightType: 3 m_BlendStyleIndex: 0 m_FalloffIntensity: 0.5 m_Color: {r: 1, g: 1, b: 1, a: 1} m_Intensity: 1 m_LightVolumeIntensity: 1 m_LightVolumeIntensityEnabled: 0 m_ApplyToSortingLayers: 00000000 m_LightCookieSprite: {fileID: 0} m_DeprecatedPointLightCookieSprite: {fileID: 0} m_LightOrder: 0 m_AlphaBlendOnOverlap: 0 m_OverlapOperation: 0 m_NormalMapDistance: 3 m_NormalMapQuality: 2 m_UseNormalMap: 0 m_ShadowIntensityEnabled: 0 m_ShadowIntensity: 0.75 m_ShadowVolumeIntensityEnabled: 0 m_ShadowVolumeIntensity: 0.75 m_Vertices:
- position: {x: 0.9985302, y: 0.9985302, z: 0} color: {r: 0.70710677, g: 0.70710677, b: 0, a: 0} uv: {x: 0, y: 0}
- position: {x: 0.9985302, y: 0.9985302, z: 0} color: {r: 0, g: 0, b: 0, a: 1} uv: {x: 0, y: 0}
- position: {x: -0.9985302, y: 0.9985302, z: 0} color: {r: -0.70710677, g: 0.70710677, b: 0, a: 0} uv: {x: 0, y: 0}
- position: {x: -0.9985302, y: 0.9985302, z: 0} color: {r: 0, g: 0, b: 0, a: 1} uv: {x: 0, y: 0}
- position: {x: -0.99853003, y: -0.9985304, z: 0} color: {r: -0.70710665, g: -0.7071069, b: 0, a: 0} uv: {x: 0, y: 0}
- position: {x: -0.99853003, y: -0.9985304, z: 0} color: {r: 0, g: 0, b: 0, a: 1} uv: {x: 0, y: 0}
- position: {x: 0.99853003, y: -0.9985304, z: 0} color: {r: 0.70710665, g: -0.7071069, b: 0, a: 0} uv: {x: 0, y: 0}
- position: {x: 0.99853003, y: -0.9985304, z: 0} color: {r: 0, g: 0, b: 0, a: 1} uv: {x: 0, y: 0}
- position: {x: 0, y: 0, z: 0} color: {r: 0, g: 0, b: 0, a: 1} uv: {x: 0, y: 0} m_Triangles: 030001000800020000000100030002000100050003000800040002000300050004000300070005000800060004000500070006000500010007000800000006000700010000000700 m_LocalBounds: m_Center: {x: 0, y: -0.00000011920929, z: 0} m_Extent: {x: 0.9985302, y: 0.99853027, z: 0} m_PointLightInnerAngle: 360 m_PointLightOuterAngle: 360 m_PointLightInnerRadius: 0 m_PointLightOuterRadius: 4 m_ShapeLightParametricSides: 5 m_ShapeLightParametricAngleOffset: 0 m_ShapeLightParametricRadius: 1 m_ShapeLightFalloffSize: 0.5 m_ShapeLightFalloffOffset: {x: 0, y: 0} m_ShapePath:
- {x: -0.5, y: -0.5, z: 0}
- {x: 0.5, y: -0.5, z: 0}
- {x: 0.5, y: 0.5, z: 0}
- {x: -0.5, y: 0.5, z: 0} — !u!1 &2743438749921625549 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 2303587278655040350} m_Layer: 0 m_Name: Attack Transform m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 — !u!4 &2303587278655040350 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2743438749921625549} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 6, y: 0, z: -1} m_LocalScale: {x: 2, y: 2, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3427063659719920997} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} — !u!1 &3441428217001971612 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 3153931062198904832} m_Layer: 0 m_Name: Down Attack Transform m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 — !u!4 &3153931062198904832 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3441428217001971612} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: -6, z: -1} m_LocalScale: {x: 2, y: 2, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3427063659719920997} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} — !u!1 &4277997539788339876 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 3427063659719920997}
- component: {fileID: 8345316024304619889}
- component: {fileID: 4312014285527962271}
- component: {fileID: 8957407249950329422}
- component: {fileID: 8668075921807760796} m_Layer: 6 m_Name: Boss Handler (1) m_TagString: Enemy m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 — !u!4 &3427063659719920997 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4277997539788339876} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children:
- {fileID: 2524676789858584298}
- {fileID: 4106419287293654058}
- {fileID: 2303587278655040350}
- {fileID: 5819815157760098064}
- {fileID: 3153931062198904832}
- {fileID: 7026905153833143961}
- {fileID: 6060635570027466028}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
— !u!61 &8345316024304619889
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4277997539788339876}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 1
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 5.3, y: 8}
m_EdgeRadius: 0
— !u!50 &4312014285527962271
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4277997539788339876}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 1
m_Constraints: 4
— !u!82 &8957407249950329422
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4277997539788339876}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 0}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3 time: 0 value: 1 inSlope: 0 outSlope: 0 tangentMode: 0 weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334
- serializedVersion: 3 time: 1 value: 0 inSlope: 0 outSlope: 0 tangentMode: 0 weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 panLevelCustomCurve: serializedVersion: 2 m_Curve:
- serializedVersion: 3 time: 0 value: 0 inSlope: 0 outSlope: 0 tangentMode: 0 weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 spreadCustomCurve: serializedVersion: 2 m_Curve:
- serializedVersion: 3 time: 0 value: 0 inSlope: 0 outSlope: 0 tangentMode: 0 weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 reverbZoneMixCustomCurve: serializedVersion: 2 m_Curve:
- serializedVersion: 3 time: 0 value: 1 inSlope: 0 outSlope: 0 tangentMode: 0 weightedMode: 0 inWeight: 0.33333334 outWeight: 0.33333334 m_PreInfinity: 2 m_PostInfinity: 2 m_RotationOrder: 4 — !u!114 &8668075921807760796 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4277997539788339876} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 8ebaf7847c670074ebdb2a016048ba5a, type: 3} m_Name: m_EditorClassIdentifier: health: 10 recoilLength: 1 recoilFactor: 1 isRecoiling: 0 speed: 10 damage: 1 orangeBlood: {fileID: 8768732011832710357, guid: d28edf6dead18434faca7cb1f0e23abc, type: 3} hurtSound: {fileID: 8300000, guid: 4b4dd7245f6104c8c8eb07ccf6b386ed, type: 3} slashEffect: {fileID: 2004286436030569933, guid: 04092d5cb3322c34d8f76d95e00af945, type: 3} SideAttackTransform: {fileID: 2303587278655040350} SideAttackArea: {x: 7.5, y: 7.5} UpAttackTransform: {fileID: 5819815157760098064} UpAttackArea: {x: 7.5, y: 7.5} DownAttackTransform: {fileID: 3153931062198904832} DownAttackArea: {x: 7.5, y: 7.5} attackRange: 6 attackTimer: 1 facingRight: 1 groundCheckPoint: {fileID: 7026905153833143961} wallCheckPoint: {fileID: 0} groundCheckY: 0.5 groundCheckX: 2 whatIsGround: serializedVersion: 2 m_Bits: 8 runSpeed: 0 attacking: 0 attackCountdown: 0 damagedPlayer: 0 parrying: 0 moveToPosition: {x: 0, y: 0} diveAttack: 0 divingCollider: {fileID: 315919253221015634} pillar: {fileID: 8226482527080914092, guid: 80381835d9c47454f856fdb96bb7d877, type: 3} — !u!1 &8958960447178865526 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 7026905153833143961} m_Layer: 0 m_Name: Ground Check m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 — !u!4 &7026905153833143961 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 8958960447178865526} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: -3.5, z: -1} m_LocalScale: {x: 2, y: 2, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3427063659719920997} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} — !u!1 &9101272760682853875 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component:
- component: {fileID: 5819815157760098064} m_Layer: 0 m_Name: Up Attack Transform m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 — !u!4 &5819815157760098064 Transform: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 9101272760682853875} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 6, z: -1} m_LocalScale: {x: 2, y: 2, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 3427063659719920997} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} This is the boss handler prefab
November 16, 2026 at 12:00 am #20150::Thank you for sharing the YAML for your Boss Handler prefab, Nirvik! Having this blueprint right in front of us illuminates the exact architecture of your boss’s physics setup, and it immediately reveals why the floor isn’t stopping the dive.
Let’s walk through the components we found inside your prefab and see how they connect to the clipping bug.
The Primary Culprit: The Boss’s Main Collider is a Trigger
If we look at the root
Boss Handler (1)GameObject (fileID: 4277997539788339876) and inspect itsBoxCollider2Dcomponent (fileID: 8345316024304619889), we find this setting:BoxCollider2D: m_Enabled: 1 m_IsTrigger: 1 m_Size: {x: 5.3, y: 8}Notice that
m_IsTriggeris set to1(True).- What this means: When a collider has Is Trigger checked, Unity treats it as an invisible sensor rather than a physical object. It will detect overlaps for code events (like
OnTriggerEnter2D), but it will never physically collide with or be stopped by solid surfaces like your floor. - How this causes the bug: Your child
Diving Collider(CircleCollider2D) also hasm_IsTrigger: 1, which is completely normal because it is meant to act as a hitbox to damage the player. However, because the boss’s mainBoxCollider2Dis also a trigger, your boss has zero solid colliders on its body. As soon as gravity or dive velocity pushes it downward, it passes straight through the floor like a ghost!
Other Important Clues in the Prefab
While we are looking at the YAML blueprint, let’s also verify a few other physics details we can see here:
- Continuous Collision Detection is Active: On your
Rigidbody2D(fileID: 4312014285527962271),m_CollisionDetection: 1confirms you already have Continuous collision detection enabled. That is great—once the collider is solid, this will prevent high-speed tunneling. Ground CheckPosition vs. Collider Size:- Your main
BoxCollider2Dhas a height (m_Size.y) of8, meaning its bottom edge sits aty = -4relative to the boss’s center. - Your
Ground Checkchild object (fileID: 7026905153833143961) is positioned aty = -3.5, and yourgroundCheckYraycast length is0.5. - Notice the math here:
-3.5 + (-0.5) = -4.0. This means your ground-check raycasts end at the exact bottom edge of yourBoxCollider2D! Once you make theBoxCollider2Dsolid, the collider might stop the boss right on top of the floor before the raycast can actually penetrate the ground to returntrue.
- Your main
whatIsGroundLayerMask: In your Boss script component,whatIsGroundhasm_Bits: 8, which corresponds to Layer 3 (2^3 = 8). Just be sure that your floor GameObjects in the scene are assigned to Layer 3!
Step-by-Step Solution
Let’s apply the fix in the Unity Editor and test the result:
- Make the Main Collider Solid:
- Select your
Boss Handler (1)GameObject (and/or the Prefab asset). - In the Inspector, find the
BoxCollider2Dcomponent. - Uncheck
Is Trigger.
- Select your
- Give the Ground Check Raycast Slightly More Reach:
- Still on
Boss Handler (1), look at your Boss script in the Inspector. - Increase
groundCheckYslightly from0.5to something like0.75or1.0(or move theGround Checkchild transform slightly lower, to aroundy = -3.8). This ensures the raycasts extend just past the bottom of the solidBoxCollider2DsoGrounded()reliably triggers the moment the boss lands.
- Still on
(Note: If you originally set the Boss’s
BoxCollider2DtoIs Triggerso the player wouldn’t get physically pushed around by the boss, let us know! There are clean ways to handle Player-to-Boss pass-through using Layers without making the boss fall through the floor.)
Where to Look Next (If Anything Still Feels Off)
Try unchecking Is Trigger on that main
BoxCollider2Dand adjustinggroundCheckYfirst!If the boss still behaves strangely during the dive after making the collider solid, could you share the
OnStateEnter()method from your dive state script (or the part ofBoss.cswhere the downward dive movement is actually applied)? Seeing how the downward force is calculated will help us make sure the movement code plays nicely with your newly solid physics body!November 16, 2026 at 7:25 am #20151::I dont know, but I thought the boss’s collider was set to trigger in the video. Also, the boss doesnt dive thru the player and just gets stuck on top of it now
November 16, 2026 at 1:30 pm #20152::Hello Nirvik! Thank you for the update. It is completely understandable that you saw the boss’s collider set to a trigger in the video—tutorials sometimes configure colliders in specific ways at earlier stages, or rely on subtle project settings that are easy to miss when following along.
What you are experiencing right now is actually a great step forward: the boss is no longer clipping through the floor!
However, by solving that first puzzle, we have uncovered the exact reason why the tutorial might have tempted you to use a trigger in the first place. Let’s look at why the boss is now getting stuck on the player’s head, and how we can give you the best of both worlds: a boss that stands solidly on the ground, yet passes right through the player during a dive.
Why the Boss is Getting Stuck on the Player
When
Is Triggerwas checked (True), the boss’s mainBoxCollider2Dhad no physical presence at all—it could pass through the player, but it also passed straight through the floor.Now that
Is Triggeris unchecked (False), the boss’sBoxCollider2Dis a solid physical object. Because your Player also has a solid collider, Unity’s physics engine sees two solid boxes trying to occupy the same space and stops the boss right on top of the player’s head.To let the boss dive straight through the player while still landing solidly on the floor, we need to tell Unity: “Keep the boss’s collider solid for the Ground, but ignore physical collisions with the Player.”
Here are the two cleanest pathways to set this up.
Method 1: Using the Layer Collision Matrix (Recommended)
This is the standard Metroidvania approach when you want enemies/bosses to walk on the ground without physically pushing or getting stuck on the player.
- Check Your Layers:
- In your prefab YAML earlier, we saw that
Boss Handler (1)is on Layer 6 (m_Layer: 6), which is likely yourEnemyorBosslayer. - Select your Player GameObject in the scene and check the Layer dropdown at the top-right of the Inspector. Make sure the Player is on its own dedicated layer (for example, a layer named
Player). If both the Player and the Ground are on theDefaultlayer, create a new layer forPlayerviaAdd Layer...and assign your Player to it.
- In your prefab YAML earlier, we saw that
- Update the Physics 2D Collision Matrix:
- In the top menu, go to
Edit > Project Settings > Physics 2D. - Scroll down to the bottom to find the Layer Collision Matrix (the grid of checkboxes).
- Find the intersection between your Player layer and your Boss / Enemy (Layer 6) layer, and uncheck that box.
- Make sure the intersection between your Boss / Enemy (Layer 6) layer and your Ground layer remains checked.
- In the top menu, go to
What this achieves: Unity’s physics engine will now completely ignore physical body-blocking between the Boss and the Player. The boss will dive straight through the player without getting stuck, and will stop cleanly the moment its solid
BoxCollider2Dhits the Ground layer!
Method 2: Ignoring Player Collision via Code (If they only pass through during the dive)
If you want the boss and player to physically block each other normally, and only want the boss to pass through the player during the dive (or if the tutorial explicitly disables collision in code), you can use
Physics2D.IgnoreCollision:// Example inside your Dive State's OnStateEnter (or Boss.cs when starting a dive): Physics2D.IgnoreCollision(bossMainCollider, playerCollider, true); // And inside OnStateExit (when the dive finishes): Physics2D.IgnoreCollision(bossMainCollider, playerCollider, false);(Note: In most 2D platformers like Hollow Knight, Method 1 is used at all times so the player never gets awkwardly trapped or stood upon by bosses!)
How Does the Boss Damage the Player Now?
You might wonder: “If we uncheck the collision matrix box between the Player and the Boss, how will the boss hurt the player?”
Wait—if you use Method 1 (unchecking the Layer Collision Matrix), Unity will ignore both solid collisions and trigger collisions between those two layers!
Let’s look at how your prefab is structured so your damage triggers still work:
- Your root
Boss Handler (1)has the solidBoxCollider2Dthat needs to hit the ground and ignore the player. - Your child
Diving Collider(CircleCollider2D) hasIs Triggerchecked, which acts as the hitbox to damage the player during the dive.
If you use the Layer Collision Matrix (Method 1), you can keep your hitbox triggers working by putting the physical body and the trigger hitboxes on different layers:
- Set the root
Boss Handler (1)to a layer (e.g.,BossBody) that collides only with Ground (unchecked againstPlayer). - Set the child
Diving Collider(and any other hitbox children) to yourEnemy/Attacklayer that does intersect with thePlayerlayer in the matrix. SinceDiving ColliderhasIs Triggerchecked, it will detect and damage the player viaOnTriggerEnter2Dwithout ever physically stopping the boss!
Give Method 1 (or Method 2 if you prefer keeping everything on the same layer) a try! Let us know how the dive feels once the boss can pass through the player, or if you’d like to look at the script that handles the player-damage detection next.
November 16, 2026 at 9:32 pm #20153::Isnt the boss supposed to damage the player if the player just touches it normally? Also there was nothing about that in the video and they got it to work. Im sorry for being picky and whatnot.
- Are you using
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: