Raycasting ignoring small sized object

I am having this issue with raycasting where the 1,1,1 scale primitive object is being ignored …but when i size it up it works just fine.
i am trying to shoot an object with my gun , by detecting the hit via raycasting i want to reduce the health
i have two scripts “shoot” and “health” ,shoot is attached to my gun and health to the “dummy” object that is to be hit

so now when i use the standard size (1,1,1) object …debug prints hitting and hp is always 100

but on increasing the size …the hit is registered and hp is reduced
can anyone help me out ? is there a better more efficient way to do the same ?

public class health : MonoBehaviour {

	public float hp=100f;
	//public Material mat;
	void Start () {
		//mat = GetComponent<Material> ();
	}
	
	// Update is called once per frame
	void Update () {
		Debug.Log (hp.ToString ());
		if (hp <= 0f) 
		{
			Debug.Log ("dummy is dead");
			//mat.color = Color.black;

		}
	}
}


public class shoot : MonoBehaviour {
	public Vector3 point;
	public float range; //set to 100	
	public float damage;//set to 10

	void Start () {
		point = transform.Find ("tip").gameObject.transform.position;	 // the tip of my gun
	}


	void Update () {
		Ray ray = new Ray(point,Vector3.forward);
		RaycastHit hit;

		if (Input.GetMouseButton (0)) 
		{

			if(Physics.Raycast(ray,out hit,range))
			{
				
				Debug.Log ("hitting!!");
		
				if(hit.collider.tag=="dummy")
				{
					Debug.Log("hitting dummy!!");
					hit.collider.gameObject.GetComponent<health>().hp-=damage;
					//hit.collider.gameObject.GetComponent<Renderer>().material.SetColor("colour",Color.red);

				}	
			}
		}

	}
}

Hello there,

In your Ray, you have Vector3.Forward, which is the same as “Vector3(0, 0, 1)”.

This means that it doesn’t take your gun orientation into account.

Instead, you should probably have point.transform.forward. Since “point” is the tip of your gun, this will make the ray go forward from the tip.

Note: This is assuming your “point”'s forward is actually pointing forward. To make sure, select the tip during gameplay, and in local mode make sure the blue arrow point in the correct direction (in front of it).

Also, to debug the ray you should probably check out DrawRay().


I hope that helps!

Cheers,

~LegendBacon