# Wall checking not working correctly (604256)

**URL:** https://discussions.unity.com/t/wall-checking-not-working-correctly-604256/604256
**Category:** 2D
**Tags:** 2D
**Created:** [November 5, 2015, 4:56pm UTC](https://discussions.unity.com/t/wall-checking-not-working-correctly-604256/604256 "2015-11-05T16:56:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![siddharth3322](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@siddharth3322](https://discussions.unity.com/u/siddharth3322)
#### Post date: [November 5, 2015, 4:56pm UTC](https://discussions.unity.com/t/wall-checking-not-working-correctly-604256/604256/1 "2015-11-05T16:56:04Z")

</div>

Basically I am working on side scrolling 2d game. For that I want to check whether player is collided with wall. I have written some code for it but can’t able to decide where I have done stupid mistake. So please guide me in this. If you need any more details then I am always available.

Code for detecting wall :

```csharp
RaycastHit2D hit = Physics2D.Raycast (wallCheck.position, Vector2.right, wallCheckDistance);

        if (Physics2D.Raycast (wallCheck.position, Vector2.right, wallCheckDistance)) {
            Debug.Log ("collider name : " + hit.collider.name);
            isDead = true;
        }

        Debug.DrawRay (wallCheck.position, Vector3.right * wallCheckDistance, Color.red);

```

Following image gives you all idea about situation. In that I have allocated player with groundCheck and wallCheck flag. At present in wallCheck section, I am detecting ground as collider response after execution of above code. Above code I have placed in Update method for continuous checking.

 ![2370145--160958--Screen Shot 2015-11-05 at 10.22.17 pm.png](https://europe1.discourse-cdn.com/unity/original/4X/0/4/2/042eba61739c179badf66b15295a45cb04dd58ba.png)

---

<div class="post-metadata">

### Author: ![siddharth3322](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@siddharth3322](https://discussions.unity.com/u/siddharth3322)
#### Post date: [November 6, 2015, 10:09am UTC](https://discussions.unity.com/t/wall-checking-not-working-correctly-604256/604256/2 "2015-11-06T10:09:36Z")

</div>

Why wallCheck object detecting collision of ground object (stage1a)?  
That is big question of mine. Please someone give me reply of this.

---

<div class="post-metadata">

### Author: ![RemDust](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@RemDust](https://discussions.unity.com/u/RemDust)
#### Post date: [November 27, 2015, 11:20am UTC](https://discussions.unity.com/t/wall-checking-not-working-correctly-604256/604256/3 "2015-11-27T11:20:12Z")

</div>

interested in this too !  
isn’t it possible that your “[Vector2](http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=Vector2).[right](http://unity3d.com/support/documentation/ScriptReference/30_search.html?q=right)” doesnt actually point to the right direction ?  
I mean, “right” for you might not be “right” for your ingame world space.  
By the way, in your debug, you’re using vector3 while you use vector2 in your cast, maybe what you see is not what you really get from your raycast…

---

<div class="post-metadata">

### Author: ![AlanGameDev](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/alangamedev/32/449237_2.png) [@AlanGameDev](https://discussions.unity.com/u/AlanGameDev)
#### Post date: [November 27, 2015, 3:45pm UTC](https://discussions.unity.com/t/wall-checking-not-working-correctly-604256/604256/4 "2015-11-27T15:45:39Z")

</div>

Few things to clarify…  
Why are you raycasting twice? Just use ‘hit’ since it’s exactly the same thing.  
Also, just a guess, but perhaps you dropped a wrong object in the inspector, or somehow the names aren’t correct. I don’t see why the example wouldn’t work.  
Also, considering it’s a very simple interaction, perhaps you could make an sscce… possibly that will allow you to debug and fix the problem yourself.

Edit: Something you can try is drawing a line from the origin to the hit point. That way you’ll be able to see exactly where the ray is hitting.
