Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ElPerro54 · May 26, 2017 at 04:51 AM · animationplatformerprojectileanimation controller

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;
         }
     }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

https://www.youtube.com/watch?v=oPQz02eSJtU

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges