My 2d ray keeps on hitting the point it comes from! Need help please

var hit : RaycastHit2D=Physics2D.Raycast(transform.position, dir,1.0);

if (hit.transform != null){

Debug.DrawRay (transform.position, dir, Color.green);
Debug.Log( hit.rigidbody.gameObject.name );
}
}

So it works perfectly except for one thing, when my player has a box collider on it keeps on hitting his own collider which isnt what i want. Is there 2d rays to ignore certain tags or a way to not hit your own collider?

Take a look at the Unity example project here.
Or u can use a layerMask : Filter to detect Colliders only on certain layers.

Also used in the Unity example.

The documentation says how to do what you need to do. It explains that there is a layer mask parameter you can use in it, so it will only hit rays on colliders that are in that layer, such as a “Ground” layer.

var hit : RaycastHit2D=Physics2D.Raycast(transform.position, dir,1.0, 1 << LayerMask.NameToLayer("Ground"));

thank you thats exactly what i needed!!