- Home /
Please help with Turret rate of fire
So I have been having some trouble with shooting in unity not button shooting but AI shooting. I followed TornadoTwins tutorials on the turret but wanted some units to shoot faster or slower than others, but found that I couldn't change anything that would change rate of fire. so I tried a lot of stuff skipping boring story....
so over all I came to use this script:
var Turret : GameObject; var Bullet : Transform; var BulletSpeed = 5000; var Character : Transform; var SavedTime = 0;
if(Vector3.Distance(Character.position, transform.position)>20) { var Shoot : AnimationEvent = new AnimationEvent(); Shoot.time = 2.166; Shoot.functionName = "SHOOT";
Turret.animation.clip.AddEvent(Shoot);
}
function SHOOT ()
{ var bullet = Instantiate(Bullet, transform.Find("X").transform.position, Quaternion.identity); bullet.rigidbody.AddForce(transform.forward * BulletSpeed);
}
Now this works just fine but it shoots twice any suggestions on making it shoot once?
Thanks Guys~
K.N.
Answer by kyle · Aug 21, 2010 at 02:40 PM
Okay this is closed guys the answer was that I had to work with the event position in the time of the shot apparently I had two animationEvents during the actual playing of the game because of the Shoot.time = 2.166;
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
tornado twins worm game tutorial turret not firing 2 Answers
Turret shooting at me 1 Answer
enemy AI script 3 Answers
I need help using mecanim... 0 Answers