Collider.IsTouchingLayers not working in 3D

I have recently been doing some testing in a 3D project on Unity. In a 2D project I made, I sensed the player touching the ground by using “Collider2D.IsTouchingLayers(Ground)” and putting anything that classified as “ground” in the “Ground” layer. This strategy worked fine in that project, but I am now trying to use the same thing in 3D and it keeps saying “Collider does not contain a definition for IsTouchingLayers” Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

private Rigidbody rb;
private Collider boxColl;
private Collider capColl;
public bool canJump = false;
[SerializeField] private LayerMask Ground;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
boxColl = GetComponent();
capColl = GetComponent();

}

// Update is called once per frame
void Update()
{

if (Input.GetKey(KeyCode.Space) && capColl.IsTouchingLayers(Ground))
{
rb.velocity = new Vector3(rb.velocity.x, 7, rb.velocity.z);
}
}

}

Does anyone know what I’m doing wrong?

Please use code-tags when posting code and not plain-text.

If you look at the docs you’ll see that this, amongst other functionality, is not there for 3D physics. Here’s the docs for Collider.

The 2D and 3D physics engines are different and while generally close in many places they are not identical.

Thank you so much! I was wondering about it. I’m fairly new to Unity, so I didn’t know about that.

1 Like

We’ve tried to keep feature parity which is why a lot looks so similar but they are completely separate and isolated systems work on by different teams as well as certain wants/needs are more important and therefore take priority in 2D over 3D.