Physics.CheckSphere get collision GameObject

Hello,
How can i get the Gameobject the Sphere (Physics.CheckSphere(GroundCheck.position, groundDistance, groundMask)) is colliding with? I have tried with the OnCollisionEnter(Collision collision) function but i didnt work out. Is there a was to get the collision GameObject?,Hello,I am currently checking a collision with a wall like this: isWallJump = Physics.CheckCapsule(WallCheckBottom.position, WallCheckTop.position, 1f, groundMask); but i need the GameObject that im colliding with.

The Physics.Check* methods are only for checking if something exists, not what. Use the Physics.Overlap* methods to know what, they return an array of the colliders.

E.g. Physics.OverlapSphere or Physics.OverlapCapsule.

3 Likes

Thank you Adrian, that helped, a lot.

I had same problem and i solved it tanks to adrian so here is my working code for groundCheck if there is anybody who have same problem :

public bool isGrounded;

//Put this into Update()
Collider[ ] hitcollider;
hitcollider = Physics.OverlapSphere(groundCheck.position, groundDistance);
if(hitcollider.Length > 0)
{
isGrounded = true;
}
else
{
isGrounded = false;
}