- Home /
Question by
F35Lightning · Apr 07, 2014 at 01:19 AM ·
transformfpsbulletgunfire
Bullet only goes in a single way
Im working on making my enemies but i recently noticed that my firing is off it didnt use to be like this i did upgrade the firing script to enable reloading but then i decressed the bullet speed and noticed then that my firing is wayy off so heres the code i might have done something else wrong but i tried everything i could and it still dosent work.
GUN FIRE CODE: #pragma strict
var MaxAmmo = 1;
var Ammo = MaxAmmo;
var Bullet : GameObject;
var Bullets = 25;
var FirePoint : GameObject;
var ShootSound : AudioClip;
var FireMode : String = "Semi";
var reloading : boolean;
var script2 : muzzleFlash;
var script3 : Recoil;
var NoAmmoSound : AudioClip;
var ReloadSound : AudioClip;
var ReloadSoundtime : int;
private var timer = 0.0;
var reloadTime = 10.0;
function Start () {
script3 = GetComponent(Recoil);
script2 = GetComponent(muzzleFlash);
}
function Update () {
if(Ammo > 0){
script3.enabled = true;
script2.enabled = true;
if(FireMode == "Semi")
{
if(Input.GetMouseButtonDown(0))
{
FireOneBullet();
audio.PlayOneShot(ShootSound); // Audio for gun
}
}
}
if(Ammo == 0){
if(Input.GetMouseButtonDown(0))
{
audio.PlayOneShot(NoAmmoSound); // Audio for gun
}
script3.enabled = false;
script2.enabled = false;
}
if(Input.GetKeyDown("r"))
{
ReloadSoundtime -= Time.deltaTime;
audio.PlayOneShot(ReloadSound);
Reload();
}
if(reloading) {
if(timer<reloadTime)
{
timer+=Time.deltaTime;
}
else
timer=0.0;
if(timer>=reloadTime)
{
Ammo = 30;
timer=0.0;
reloading = false;
}
}
}
function FireOneBullet ()
{
var Bullet = Instantiate(Bullet, FirePoint.transform.position, transform.rotation);
Ammo --;
}
function Reload ()
{
ReloadSoundtime ++;
if(Ammo < MaxAmmo && Bullets > 0)
{
reloading = true;
}
}
And heres the BULLET SPEED CODE:
#pragma strict
var BulletSpeed : int;
function Start () {
rigidbody.AddForce(transform.forward * BulletSpeed);
}
ANY HELP WILL BE APPRICIETED THANKS GUYS!
Comment
Take a look at the rotation of the object your GunFireScript is attached to. The rotation of the bullet will be exactly the same as that is how you set it up.
If it answered your question, please validate the answer by ticking the check box on the left side of the answer.