Hi all.
I’ve been playing around with this ammo script and it’s working good (well most of it) except the shooting direction. When I’m facing straight forward sometimes it shoots left, right it’s tweaky. Can’t really get one direction. Cannot face only one way, or for example when looking down it shoots sometimes on the side sometimes up sometimes in the ground.
var speed = 3.0;
var rotateSpeed = 3.0;
var bullitPrefab:Transform;
var currentBullets = 15;//This is the amount RIGHT NOW that the gun has. (should be 0 by default.)
var totalBullets = 15; //TOTAL amount the gun will have
var bulletsDisplayed : GUIText;
function Update ()
{
// Move? forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
if(Input.GetButtonDown("Fire1"))
{
if (currentBullets > 0) //only shoot if you have ammo.
{
var bullit = Instantiate(bullitPrefab, GameObject.Find("Main Camera").transform.position,Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 3500);
currentBullets--; //subtract one
}
else //if you have less than 1 bullet
{
//perform reload animation
currentBullets = totalBullets; //reset ammo count
}
}
bulletsDisplayed.text = "Current amount of bullets is " + currentBullets;
}
What might be the problem? Thanks.