- Home /
How do you animate a projectile?
Hey guys, Im making a 2d platformer shooter where you shoot fireballs. Got the character and shooting animation done, but I need help on animating the actual projectile. Should I make another Animation Controller? Or do this on the actual player controller? Havent really found any tutorials covering this, just the basic of movement, shoot, etc. This is the code for shooting:
if (Input.GetKeyDown(KeyCode.F) && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
anim.SetTrigger("isShooting");
Invoke("fireProjectile", 0.5f);
}
void fireProjectile()
{
GameObject clone;
clone = Instantiate(projectile);
clone.transform.SetParent(projCheck.transform);
clone.transform.localPosition = Vector3.zero;
if (!facingRight)
{
projCheck.transform.localPosition = new Vector2(-0.3f, -0.03f);
clone.transform.localScale = new Vector3(-5.01f,4.13f);
clone.GetComponent<Rigidbody2D>().velocity = -transform.right * projSpeed;
}
else if (facingRight)
{
projCheck.transform.localPosition = new Vector2(0.3f, -0.03f);
clone.GetComponent<Rigidbody2D>().velocity = transform.right * projSpeed;
}
}
Answer by FM-Productions · May 26, 2017 at 06:15 AM
HI,
I'd say you have to attach a separate Animator or Animation component to the projectile, since it is a gameObject on its own (not technically belonging to the player character). I also think you do not need a Animator controller, since the projectile should only loop the same animation?
After a few seconds of searching youtube, I found this video. It seems like it is what you are looking for: Shooting an animated projectile in an 2D game.
Your answer

Follow this Question
Related Questions
How can I change my AnimatorState instantly? 1 Answer
A problem with Animation Rigging package 0 Answers
Collision occurring when it should not! Help! 1 Answer
animations dont play properly, prefab projectile does not move anymore, why? 1 Answer
Is posible to make an universal transition tree for many GameObjects? 1 Answer