Issue with weapon script

I am trying to create (very) basic weapon system in my game, and I am running into a problem. The projectiles, which are rigidbody objects, just pop up and seem to go for a very short distance in a random direction, and then fall to the floor(I know the gravity effect is supposed to be there, I want that; the error is just with their direction). Now, using the exact same code, this use to work more or less how I wanted it to, but I changed the variable holding the projectile object and the variable holding the instantiated projectile from a rigidbody to a gameobject, and then back again and now it does this improper effect. Could someone maybe tell me what is wrong with the script? And if there is a better way of doing it?

//Inspector variables
var playerHealth : int;
var playerWeapon : int;
var playerAmmo : int;
var weaponArr = new Array();
var projectile : Rigidbody;

//Weapon array
//weaponArr.length = 5;
//weaponArr[0]=

function Update () {
	ShootController();
}	

function ShootController (){
	
	if (Input.GetButton("Fire1"))
	{
		if (playerAmmo > 0){
			var clone : Rigidbody;
			clone = Instantiate(projectile, transform.position,transform.rotation);
			clone.velocity = transform.TransformDirection(Vector3.forward * 50);
			playerAmmo -= 1;		
		}
	}
}

Thanks for your help and time!

If you are spawning a rigidbody inside a rigidbody, that will cause problems such as your projectile flying in a random direction. Try turning rigidbody off on the projectile. I like to use triggers for projectiles and make enemies react to them through OnTriggerEnter to avoid any unwanted physics behaviour. Aternatively if you want to keep both as rigidbodies then use the Layer dropdown option next to Tag. Give them each a new layer name, then go to Edit->ProjectSettings->Physics and uncheck the collision detection for layers you selected.

You should use RigidBody.AddForce instead of setting the velocity. See this answer for the details, it does pretty much exactly what you want to do.

If its being instantiated inside a another rigidbody then it will often shoot off in a random direction.

Using rigidbodies to shoot bullets is pretty bad I think. They are ok for very slow bullets.

  1. They slow performance.
  2. I had all sorts of problems with them going through objects when going fast.

You are better off using raycast to calculate if they hit anything. And using rigidbody.addforce to add force to objects hit.