# My Tank Turret Wont Fire?

So i am working on a top-down tank shoot em up and i have the controls working but not the cannon. I think im doing it right but its not fireing when i press my mouse 0 button have a look.

``````function update()
{
if(Input.GetKeyDown(KeyCode.Mouse0))
{
var bullet = Instantiate(bulletPrefab, transform.Find("cannonShoot").transform.position, Quaternion.identity);
}
}

``````

"cannonShoot" is a empty game object in front of my tank's barrel

Also i need a way to rotate to a specific angle over a period of time... currently im just using snap to angles for movements as shown below.

``````private var z = 0.0;
private var x = 0.0;
private var y = 0.0;
function Update()
{
var leftButton = Input.GetKeyDown(KeyCode.A);
var upButton = Input.GetKeyDown(KeyCode.W);
var rightButton = Input.GetKeyDown(KeyCode.D);
var downButton = Input.GetKeyDown(KeyCode.S);
var angles = transform.eulerAngles;
//Basic Movements
if(leftButton)
{
var rotationLeft = Quaternion.Euler(x, -90, z);
transform.rotation = rotationLeft;
}
if(upButton)
{
var rotationUp = Quaternion.Euler(x, 0, z);
transform.rotation = rotationUp;
}
if(rightButton)
{
var rotationRight = Quaternion.Euler(x, 90, z);
transform.rotation = rotationRight;
}
if(downButton)
{
var rotationDown = Quaternion.Euler(x, -180, z);
transform.rotation = rotationDown;
}
//Two buttons at once
if(downButton && leftButton)
{
var rotationDownLeft = Quaternion.Euler(x, 45, z);
transform.rotation = rotationDownLeft;
}

}

``````

Any help would be appreciated.

i do have an alternative although it it's self has a few problems, if i aim up (as i happen to be making a tank game 2) it still fires forward instead of up, and if i turn the cannon of the tank and fire it will fire the direction of the tank body and not the gun... but it fires :)

``````//Shooting

``````

var bullitPrefab:Transform;

(i don't know how 2 do the fancy script thing on here) but this at the top with other variables

if(Input.GetButtonDown("Fire1")) { var bullit = Instantiate(bullitPrefab, GameObject.Find("spawn").transform.position, Quaternion.identity); bullit.rigidbody.AddForce(transform.forward * 7000); }

and this somewhere within the moving stuff, (your main script btw) the number above (7000) make it bigger to fire faster or lower to slow.

function OnCollisionEnter(){ Destroy(gameObject);

} function Update () { }

make a new script and fill all of it with the above and but it on the bullet to make it disappear on collision, and make the bullets rigidbody, (remove gravity on bullets if you want them not to fall) with the disappear bit it will still have effects on like other rigidbody objects so its good :) hope this helps.... bloody hell i've written allot. :O

very sorry, forgot 2 add that you will need 2 make an object with no collider or render were u want the bullets to spawn and call it "spawn" (no capitals)