Raycast not working at short range

Im trying to use a raycast for a punch but its not working with limited range. It either travels the entire map or doesnt make a ray at all
Heres the script snippet

var HitRay : RaycastHit;
var PlayRange = transform.TransformDirection(Vector3(0,0,0.0001));
//if (Physics.SphereCast((transform.position + Vector3.up * 0.75), 1, PlayRange, HitRay)){
if (Physics.Raycast(transform.position, PlayRange, HitRay)){
HitRay.transform.SendMessage ("HitPunch");
Debug.DrawLine(transform.position, HitRay.point, Color.red);
}
}

As you can see, I’ve tried both Raycast and Spherecast
Thanks

The Raycast() you are using is Raycast(start, direction, hit). Unlike Debug.Drawray(), the length of the direction vector does not matter. So you can replace ‘PlayRange’ with ‘transform.forward’. In this form of Raycast(), the distance of the Raycast() is the fourth parameter. When not specified, Mathf.Infinity is used.

You likely want:

 if (Physics.Raycast(transform.position, transform.forward, HitRay, range)){  

…where ‘range’ is some small value that takes the ray beyond any mesh on the game object with the above script.

You may want to put a:

 Debug.Log(HitRay.name+", "+HitRay.tag);

As the first line inside your ‘if()’ so that you can see if you are hitting something you don’t expect.