Unity 4 Raycast Broken.

So, I got this code, and according to the API it should work… The ray casted is meant to be infinitely long, but instead its like 0.00000000000000001 long.

enter code hereusing UnityEngine;
using System.Collections;

public class Raycast : MonoBehaviour {

	void Update(){
		Vector3 fwd = transform.TransformDirection(Vector3.forward);
		RaycastHit hit;

		if(Physics.Raycast(transform.position, fwd, out hit)){
			if(hit.collider.gameObject.tag == "Vehicle"){
				print ("Enter Vehicle");
                   //Do something if this would work

using layer mask will make ray to ignore some layers

LayerMask raymask=~(1 << 8); //this will exclude layer 8 so put your player to layer 8

    if(Physics.Raycast(transform.position, fwd, out hit,Mathf.Infinity,raymask))

For Debug.DrawRay the direction vector is what determines the distance of the ray. Since the values for Vector3.forward are (0,0,1) it will only shoot 1 unit out. You can multiply it by a scalar value to (Vector3.forward * 5) to increase the distance.

For Physics.Raycast the length of the raycast is determined by the distance parameter which can be found in some of the variations of the Physics.Raycast method. If no distance is specified then the distance is equal to Mathf.Infinity like @Bunny83 pointed out.

You can use Physics.Raycast(Ray ray, out RaycastHit hitInfo, float distance) version and get the ray from doing Ray ray = m_camera.ScreenPointToRay(centerOfScreen); and see if that works for you.