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 AsAnAsterisk · Jun 23, 2017 at 11:34 PM · animationscripting problemcollideranimatorcolliders

How to have a collider inactive only during attack animation and not during 'charging' animation?

When the player holds mouse 1, I want a charging animation to play once, and the attack animation to then loop. I have the animations themselves down, and a collider is activated upon attacking, however the collider is also present while charging, as the charging animation leads into the attack animation. How do I make it so that the collider is only active during the attack animation.

 public class Hand : MonoBehaviour {
 
     private Animator anim;
     public CapsuleCollider cc;
 
     // Use this for initialization
     void Start () {
         anim = GetComponent<Animator>();
 
         cc.enabled = false;
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetButton("Fire1"))
         {
             anim.SetBool("IsNoInput", false);
             anim.SetBool("IsCharging", true);
             anim.SetBool("IsAttacking", false);
 
             
         }
         else
         {
             anim.SetBool("IsNoInput", true);
             anim.SetBool("IsCharging", false);
             anim.SetBool("IsAttacking", false);
         }
         
         
         
         if (anim.GetBool("IsAttacking") == true)
         {
         
         
         cc.enabled = true;
         
         }
         if (anim.GetBool("IsAttacking") == false)
         {
         cc.enabled = false; 
         }
         
         
      }
         
         
     public void ActiveCollider(int active)
     {
         if (active == 0)
             cc.enabled = false;
         else
             cc.enabled = true;
     }
 
    }

This current code has the charging animation play, but it stops at the last frame and doesn't move on to the attack animation. If it helps at all the charging animation is .708 seconds long.

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
3
Best Answer

Answer by cstooch · Jun 23, 2017 at 11:48 PM

I wonder if animation events are your best bet here.

You basically would have function(s) to disable/enable the collider. In your animation for charging you set up an event to call the function for disabling. In your animation for attacking, you set up an event to call the function for enabling.

That may work.

https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

These events can also be good for switching animations too, like you could put an event right at the end of charging animation that turns the charging animation parameter off and the attack animation on (if mouse is held down, I think you'd want to put)

Comment
Add comment · Show 4 · 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
avatar image AsAnAsterisk · Jun 23, 2017 at 11:53 PM 0
Share

I've considered animation events. I'm fairly new to unity, and while I know where to find them and can put the events at the correct places, I'm unsure what to put for function to have it do anything.

avatar image cstooch AsAnAsterisk · Jun 24, 2017 at 12:07 AM 0
Share

That isn't too tough to explain, no worries. I was actually brand new to them as well, up until last week when I needed to figure out something for my game.

So, basically your animation event can call any function that is attached to a script on the game object your animation is attached to.

So you really already have everything set up for the collider part as far as I can tell. You'll need to remove some of the other code you're doing because that will just be confusing things. But basically your event will call the function ActiveCollider , and you set int value to 1 or 0 (it passes as parameter), and for "Object" in the animation event, you put your script that this function is in... (Hand??).You'd also have to create a function that just simply sets your various animation parameters.. like a function to set the parameters so that your state for the charge is called, and a function to set the parameters so that your state for the attack is called.

I hope that gets you started.

That link I sent actually explained how to add an animation event in a way I thought was a little less easier to understand though. I know you can double click on the state in the animator, and it will bring up your animation in the inspector... and there's an Events section where it seemed a lot more intuitive...

It's right below where you have all those checkboxes for Loop time, loop pose, baking rotation into pose, etc...

avatar image AsAnAsterisk cstooch · Jun 24, 2017 at 01:15 AM 0
Share

Thanks for the help! I got it working! All I really had to do was set an animation event at the beginning of the attack animation to turn the collider on and an event at the start of the idle animation to turn it off.

avatar image cstooch AsAnAsterisk · Jun 24, 2017 at 01:16 AM 0
Share

Awesome!

Now you're an animation event pro! lol

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

198 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

collider animation problem 1 Answer

Character Animator controller/movement 1 Answer

Is there a new retargetting system for the animation in 5.5? 1 Answer

How to rotate spine by the script, while an animation from the animator is playing? 0 Answers

How do you allow the joints in a character to freely fall based on gravity? 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