'Collision Detection with Raycast in Unity
The problem is about as simple as it sounds. I'm trying to use a raycast to determine if a player is on the ground in a 2D Unity Game. My code is this:
RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, 40, World);
if (hit.collider != null)
{
print("touching");
}
I also have a public LayerMask World; up above and the layer "World" is set on the object I want to detect collisions to.
I'm pretty new to this so I'm not sure why the raycast isn't working.
Solution 1:[1]
Unchecking "Queries start within collider" in the setting solved the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TinyManager |
