Question by
kmart94 · Jun 20, 2019 at 05:47 AM ·
collisioncollision detectionground detection
Physics2D.Raycast not working with LayerMask
Im using the code below to detect the ground.
Vector2 origin = new Vector2(0,-.4f);
origin = (Vector2)transform.position + origin;
int mask = LayerMask.GetMask("RayCastGroundCheck");
RaycastHit2D ray = Physics2D.Raycast(origin, Vector2.down, .1f, mask);
if (ray.collider != null)
{
Vector2 currentNormal = ray.normal;
if (currentNormal.y > minGroundNormalY)
{
m_isGrounded = true;
m_groundNormal = currentNormal;
print("Grounded");
}
}
else print("Hit Nothing");
Debug.DrawLine(origin, Vector2.down * .1f + origin, Color.white);
In my collision settings I have everything in the "RayCastGroundCheck" layer unchecked except the "Ground", and "platform" layer. When I run in game it never detects the ground even though all ground is set to the ground layer. NEED HELP!
Comment
If your ground and platforms are in the ground
and platform
respectively, and if you want your raycast to detect the ground and platform, then your mask is clearly wrong....
int mask = Layer$$anonymous$$ask.Get$$anonymous$$ask("ground", "platform");
Your answer
Follow this Question
Related Questions
Having the worst time making OnCollision work... Strange. 0 Answers
Collision issue, Plz help 1 Answer
OnTriggerExit not working 0 Answers
Cube wont destroy on collision 0 Answers
Colliders for tunnels 0 Answers