- Home /
Question by
Anthonylinx · Feb 11, 2014 at 03:34 AM ·
colliderraycasthit2dcollide
Raycast2D Hitting Collider of object I'm raycasting from?
Hey everyone, right now I'm trying to send a raycast from an enemy in the direction of my player but it seems the raycast is hitting the collider on my enemy and triggering.
Vector2 vecToPlayer = m_pTarget.transform.position - transform.position;
RaycastHit2D hit = Physics2D.Raycast(new Vector2(transform.position.x,transform.position.y),vecToPlayer);
if(hit.collider.gameObject==m_pTarget )
This is all I'm doing but currently hit.collider is equal to this.collider. Is there any way to ignore my collider?
Comment
Best Answer
Answer by getyour411 · Feb 11, 2014 at 03:36 AM
Give it a layerMask and tell it to ignore 'this'
Your answer

Follow this Question
Related Questions
OnCollisionEnter2D is not working 0 Answers
Raycast 2D hits sprite with collider, but returns error when not hitting any collider 2 Answers
How to detect collision between 2 objects while checking are they the ones that need to collide? 1 Answer
Why is my object getting stuck in the edge of other objects? 2 Answers
Counting colliders 2 Answers