# RaycastHit2D problem

**URL:** https://discussions.unity.com/t/raycasthit2d-problem/221504
**Category:** Questions & Answers
**Created:** [March 16, 2019, 4:19pm UTC](https://discussions.unity.com/t/raycasthit2d-problem/221504 "2019-03-16T16:19:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![alex174](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@alex174](https://discussions.unity.com/u/alex174)
#### Post date: [March 16, 2019, 4:19pm UTC](https://discussions.unity.com/t/raycasthit2d-problem/221504/1 "2019-03-16T16:19:28Z")

</div>

Help me figure out what’s wrong.

I do a Raycast detection:

```
    private void Check()
    {
        float high = 1.1f, step = 0.35f;
        for (float i = -0.1f; i < high; i += step)
        {
            RaySidePointStart = transform.up * i + transform.position;

            RaycastHit2D RaySide = Physics2D.Raycast(RaySidePointStart, vectorSideRay,rayDistanceSide, LayerWall);
            Debug.DrawRay(RaySidePointStart, vectorSideRay * rayDistanceSide, Color.blue);

            if (RaySide.collider != null)
            {
                TouchedWall = true;
                Debug.Log("This is WALL!!!");
            }
            else //if (RaySide.collider == null)
            {
                TouchedWall = false;
            }
    }

```

and this is what happens:

[134843-рис1-2-3.jpg|134843]

Why the flag “TouchedWall” does not work when the top ray does not touch the collider?

---

<div class="post-metadata">

### Author: ![badadam](https://avatars.discourse-cdn.com/v4/letter/b/cc9497/32.png) [@badadam](https://discussions.unity.com/u/badadam)
#### Post date: [March 16, 2019, 4:45pm UTC](https://discussions.unity.com/t/raycasthit2d-problem/221504/2 "2019-03-16T16:45:33Z")

</div>

Did you add collider to the bottom box or wall.
