How to make sure that the raycast points in the right direction?

So this the script I currently am using but for some reason the raycast always points at other direction

var Hit : RaycastHit;
	
Debug.DrawLine( transform.localPosition, transform.forward * 100 , Color.blue);
	
if( Physics.Raycast( transform.localPosition, transform.forward * 100, Hit))
{
		Debug.Log(Hit.collider.name);
}

This is the image. As you can see, the raycast is not pointing along the local z-axis as
it was meant to.

23446-photo.png

The major problem here is that you are using Debug.DrawLine() which takes two positions, but you are passing it a position and direction. Change to DrawRay():

 Debug.DrawRay( transform.position, transform.forward * 100 , Color.blue);

The second problem is that Rays are cast in world space, but you are using ‘localPosition’ for both the Raycast() and the drawing. Change to using ‘transform.position’ in both places.