RayCasting 2D

Hey, so im having this problem. Im getting an error. Any ideas whats wrong here?
-Thanks!:slight_smile:

        Ray2D ray = new Ray2D(transform.position, rayPosInc);

        Debug.DrawRay(transform.position, rayPosInc, Color.blue);

        if (Physics2D.Raycast(ray, out hit)) //This is where i get the error;
{
//code...
}

What error are you getting? Also, is your “hit” variable a RaycastHit2D?

The best overloaded method match for `UnityEngine.Physics2D.Raycast(UnityEngine.Vector2, UnityEngine.Vector2, float)’ has some invalid arguments. Yes it is a RaycastHit2D.

Ray casting in 2D is different from in 3D. Check out the docs above. The method returns the RaycastHit2D directly, rather then a bool. No need to use the out keyword.

You might also want to check out line cast.

Yeah, i looked at that API previously and i didnt knew how to fix it, but now that i’ve checked it again i actually fixed it… Thanks!:smile: