Question by
Torbaz · May 08, 2019 at 08:39 AM ·
2drigidbodyraycast2d-physicsraycasthit2d
Raycast not detecting bullet
Debug.DrawRay(transform.position, transform.TransformDirection(-Vector3.right) * 1f, Color.green, 0.05f, false);
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.TransformDirection(-Vector3.right));
if (hit.rigidbody.gameObject.layer != 9)
{
Debug.Log(hit.rigidbody.gameObject.name);
}
The bullet clearly passes through the ray and is not being detected. If I do not have the if statement the console is spammed with messages that is detected its self. I'm not sure what the issue is. Thank you for your time
Comment
Your answer
Follow this Question
Related Questions
Rigidbody blocking raycasts 2D 0 Answers
Hookshot in Unity 2D not working,Hookshot 2D not working 0 Answers
Raycast2D 360 Rotation 0 Answers
Select from multiple character to move 0 Answers
2D raycast not working 0 Answers