Raycast off empty gameobject rather then camera.

I want to cast a ray(8 actually) from my airplanes gun(s). The problem is my script is designed to shoot the ray from the center of the camera. I need a way to project the ray forward from my gun(s).

#pragma strict

var Effect : Transform;
var TheDammage = 100;

function Update () {

	var hit : RaycastHit;
	var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
	
	
	if(Input.GetMouseButtonDown(0)){
		if(Physics.Raycast (ray, hit, 100))
			{
				var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
				
				Destroy (particleClone, 3);
				
				hit.transform.SendMessage("ApplyDamage", TheDammage, SendMessageOptions.DontRequireReceiver);
			}
			
	}

}

That code is using a specific shortcut to look from the camera to a specific point on the screen. But, in general, you can raycast “in the world” from any 3D point, in any 3D direction.

Looking at other examples of raycasts should let you see how it’s done. For example, a player shooting a bullet is sometimes a raycast from the gun, in the direction it faces.

This line should help you, it casts from the object that it is on, in the objects forward direction, with “fRaycast_Distance” distance and “lmPlayer” layermask.

if (Physics.Raycast (transform.position, transform.forward, hit, fRaycast_Distance, lmPlayer)) {