- Home /
Question by
chimchim · Oct 18, 2014 at 04:41 PM ·
raycastcollider2d
Raycasthit2D return wrong collider
So i am making my own 2D physics using raycasts and its been working fine so far. But when i try to get information about the colliders i hit it gives me the wrong data.
hit = Physics2D.Raycast(new Vector2(x, y), new Vector2(0, dir), Mathf.Abs(deltaY + (dir * skin)), 1 << 11);
if (hit.collider != null)
{
Debug.Log(collider.transform.position.z + " " + collider.transform.localScale + " " + collider.gameObject.name);
So the Hit.collider returns my own 2D character, even though it has the wrong layermask and a disabled collider (wtf?).
Comment
Answer by 767_2 · Oct 18, 2014 at 04:56 PM
you should say
Debug.Log(hit.collider.transform.position.z + " " + hit.collider.transform.localScale + " " + hit.collider.gameObject.name);
Your answer
![](https://koobas.hobune.stream/wayback/20220613165349im_/https://answers.unity.com/themes/thub/images/avi.jpg)