- Home /
Animation Play On Bullet Shot
Hi everyone! I tend to make "on bullet shot" animation playing dependency which means I need shooting animation being played EVERY TIME AND ONLY AFTER BULLET SHOOTS OUT. Here's my script:
private var _animation : Animation;
var Bullet : Transform;
var Speed = 500;
var spawnPoint : Transform;
var Counter = Time.deltaTime;
var RateOfFire = 0.250000;
var target : GameObject;
function Shoot() {
yield WaitForSeconds(0.1);
Counter += Time.deltaTime;
if(RateOfFire<Counter){
var shotRapid = Instantiate(Bullet, spawnPoint.transform.position,
Quaternion.identity);
shotRapid.rigidbody.AddForce(transform.forward * Speed);
Counter=0;
}
if (Counter>=0){
target.animation.CrossFade("shoot1",0.2);}
}
The problem here's that animation still can randomly be played before bullet gets out or after. I've also tried on speed dependency (if Speed >=0), but it doesn't work properly. I think I need to identify when bullet starts its' movement and tell animation "shoot1" to play after that. But how can I do this? Thanks in advance :)
Answer by ahmed.yahia · Sep 12, 2013 at 09:23 PM
i guess the problem at counter = 0;
function Shoot() {
yield WaitForSeconds(0.1);
Counter += Time.deltaTime;
if(RateOfFire<Counter){
var shotRapid = Instantiate(Bullet, spawnPoint.transform.position,
Quaternion.identity);
shotRapid.rigidbody.AddForce(transform.forward * Speed);
Counter=0;
}
if (Counter>=0){
target.animation.CrossFade("shoot1",0.2);}
}
try this function...
function Shoot() {
target.animation.CrossFade("shoot1",0.2);
yield WaitForSeconds(0.1);
Counter += Time.deltaTime;
if(RateOfFire<Counter){
var shotRapid = Instantiate(Bullet, spawnPoint.transform.position,
Quaternion.identity);
shotRapid.rigidbody.AddForce(transform.forward * Speed);
Counter=0;
}
}
There is no sense in putting animation.CrossFade at the very beginning of Coroutine since I need animation being played ONLY AFTER BULLET SHOOTS OUT. Btw Counter is not the best idea here as for if statement to enable animation's playback. So I'm trying to find another way to achieve that result. Any ideas?
Your answer
Follow this Question
Related Questions
Bullets will not fire forwards 1 Answer
Get animation work 1 Answer
How to Sync bullet spawn with shoot animation 0 Answers
Shooting & Animation Problem 1 Answer