Shooting & Animation Problem

I’ve got shooting script, here is a part of it:

var Bullet : Transform; var Speed = 500; var spawnPoint : Transform; var RapidFire = true; var SingleFire = false;

//RateOfFire private var Counter = Time.deltaTime; var RateOfFire = 0.250000;

function FixedUpdate () {

    if
    (RapidFire ==true){
     
    if
    (Input.GetButtonDown("Action") && Input.GetButton("Aiming")){
    shooting=true;
    animation.CrossFade("shoot");
    }
     
    if
    (Input.GetButtonUp("Action") && Input.GetButton("Aiming")){
    shooting=false;}
     
    if
    (shooting==true){ Counter += Time.deltaTime;
     
    if
    (RateOfFire < Counter){
    var shotRapid =Instantiate(Bullet, GameObject.Find("spawnPoint").transform.position, Quaternion.identity);
     
    //speed
    shotRapid.rigidbody.AddForce(transform.forward * Speed);
    Counter=0; }
    }
    }
    } 

The question is how to synchronize shooting with my animation. It’s 3rd person shooter I’m working at and I’ve got my character animation being looped. The shot itself should be performed approximately at 0.58 second after pressing shoot button and animation get started. After that gun recoil follows within animation and exactly before that a shot must be performed. I wanna make a bullet shot depending on animation timeline’s position. Nonetheless it’s hand gun I’ve decided to make it fire all the time on a low firing rate, when “shooting” button’s pressed. Using this script I can control firing rate, but it still won’t give me exact synchronization with the animation. So the thing I wanna achieve most is to make shooting action become dependent on my “shoot” animation played. And one more - still can’t get bullets fly straight forward the direction of a gun (if I shoot upwards it still shoots forward). But the script seem to be all right. Thanks in advance for your help :slight_smile:

If you created your animation in unity you can right click the top portion of the timeline (top half of the light grey area). From here you can make a call to a function in a script attached to the object.

For example I have an axe weapon and I make a call to attackDamage() so that the axe hits the player then causes damage so when the player health is < 0 he does not start falling before being struck.