|
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.
"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.
Any help would be appreciated.
(comments are locked)
|
|
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 :)
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
(comments are locked)
|
|
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)
(comments are locked)
|

I wouldn't recommend using Find every time you shoot. If the cannonshoot game object never changes just store a reference to it, it'll be much faster