So whenever I fire a bullet the tracer follows it like it’s supposed to but it messes up a lot. To describe what I mean here is a video. It only works sometimes (when it comes out straight)
Here is the script
var Range : float = 1000;
var Force : float = 1000;
var Clips : int = 3;
var BulletsPerClip : int = 10;
var ReloadTime : float = 2;
var BulletsLeft : int = 0;
var ShootTimer : float = 0;
var ShootCooler : float = 0.9;
public var ShootAudio : AudioClip;
public var ReloadAudio : AudioClip;
var Damage : int = 10;
var MuzzleFlash2 : Renderer;
var MuzzleLight2 : Light;
var Trail : GameObject;
function Start ()
{
BulletsLeft = BulletsPerClip;
MuzzleFlash2.enabled = false;
MuzzleLight2.enabled = false;
}
function Update ()
{
if(ShootTimer > 0){
ShootTimer -= Time.deltaTime;
}
if (ShootTimer < 0){
ShootTimer =0;
}
if (Input.GetButtonDown("Fire2") BulletsLeft)
{
if(ShootTimer == 0){
PlayShootAudio();
RayShoot();
ShootTimer = ShootCooler;
MuzzleOn();
}
}
if(Input.GetButtonDown("Reload"))
{
Reload();
}
}
function RayShoot ()
{
//GameObject.Find("GunName").animation.Play("Shoot");
var hit : RaycastHit;
var DirectionRay : Vector3 = transform.forward;
var obj = Instantiate (Trail, transform.position, Quaternion.identity) as GameObject;
obj.rigidbody.AddForce (DirectionRay * Force, ForceMode.VelocityChange);
Debug.DrawRay(transform.position, DirectionRay * Range, Color.red);
if(Physics.Raycast(transform.position , DirectionRay , hit, Range)){
if(hit.rigidbody){
hit.rigidbody.AddForceAtPosition(DirectionRay * Force, hit.point);
hit.collider.SendMessageUpwards("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
BulletsLeft --;
if (BulletsLeft < 0){
BulletsLeft = 0;
}
if (BulletsLeft == 0){
Reload();
}
}
function Reload ()
{
//GameObject.Find("GunName").animation.Play("Reload");
PlayReloadAudio();
yield WaitForSeconds(ReloadTime);
if (Clips > 0){
BulletsLeft = BulletsPerClip;
Clips -= 1;
}
}
function PlayShootAudio ()
{
audio.PlayOneShot(ShootAudio);
}
function PlayReloadAudio ()
{
audio.PlayOneShot(ReloadAudio);
}
function MuzzleOn ()
{
MuzzleFlash2.renderer.enabled = true;
MuzzleLight2.enabled = true;
yield WaitForSeconds(0.02);
MuzzleFlash2.renderer.enabled = false;
MuzzleLight2.enabled = false;
}