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 _bearzerk · Apr 02, 2017 at 12:15 PM · animatormecanimcombo

Mecanim Combo Tree returning to Idle State

I've been bashing my head over this and trying to find similar answers in the forums but no luck so far. Basically I want to set up a super simple combo system for a player:

{1,} {1, 2,} {1, 2, 3,} {1, 4,} {5,}

Better visualised here: alt text

It transitions between states well, it's just getting it to go back to idle after either a partial or full combo. I've tried setting up a Queue system that basically houses an enum for the state of each of these animation states, and if that queue is ever empty to return to state 0 (idle) however that now stops be going beyond the combo of just 1st (Swing/Throw) so I'm unable to do anything more than 1 attack.

Code as follows: using UnityEngine; using System.Collections; using System.Collections.Generic;

 public class AnimationScript : MonoBehaviour {
 
     //Setup private Animation component for the player
     private Animator playerAnim;
     //Setup parameter variable for AnimationTree
     private int MousePressVal;
     //Setup private enum to help transition Animation states
     enum PlayerAnimationState
     {
         idle,
         firstswing,
         secondswing,
         slam,
         firstthrow,
         secondthrow,
     };
     //Private enum Variable
     PlayerAnimationState pas;
     //Set up queue for linking back to Idle
     private Queue<int> attackQueue = new Queue<int>();
 
     // Use this for initialization
     void Start () {
         //Set private Animation component to the Animation component attached to this item
         playerAnim = GetComponent<Animator>();
         pas = PlayerAnimationState.idle;
     }
     
     // Update is called once per frame
     void Update () {
         if(Input.GetMouseButtonUp(0))
         {
             //Left Mouse Press
             MousePressVal = 0;
             PlayAnimationTree(MousePressVal);
         }else if (Input.GetMouseButtonUp(1))
         {
             //Right Mouse Press
             MousePressVal = 1;
             PlayAnimationTree(MousePressVal);
         }
     }
 
     void FixedUpdate()
     {
         if(attackQueue.Count > 0)
         {
             playerAnim.SetInteger("EnumPAS", attackQueue.Peek());
             attackQueue.Dequeue();
         }else
         {
             pas = PlayerAnimationState.idle;
             playerAnim.SetInteger("EnumPAS", (int)pas); 
         }
     }
 
     void PlayAnimationTree(int MouseAttackVal)
     {
         switch(MouseAttackVal)
         {
             case 0:
                 if(pas == PlayerAnimationState.idle)
                 {
                     Debug.Log("1st Swing Queued");
                     pas = PlayerAnimationState.firstswing;
                 }else if(pas == PlayerAnimationState.firstswing)
                 {
                     Debug.Log("2nd Swing Queued");
                     pas = PlayerAnimationState.secondswing;
                 }else if(pas == PlayerAnimationState.secondswing)
                 {
                     Debug.Log("Slam Queued");
                     pas = PlayerAnimationState.slam;
                 }
                 break;
             case 1:
                 if(pas == PlayerAnimationState.idle)
                 {
                     Debug.Log("1st Throw Queued");
                     pas = PlayerAnimationState.firstthrow;
                 }else if(pas == PlayerAnimationState.firstswing)
                 {
                     Debug.Log("2nd Throw Queued");
                     pas = PlayerAnimationState.secondthrow;
                 }
                 break;
         }
         attackQueue.Enqueue((int)pas);
         //playerAnim.SetInteger("EnumPAS", (int)pas); 
     }
 }
 

So my question is now: How the hell do I allow for a lag time which allows for a 2nd and possible 3rd attack swing for the player as it just snaps back to Idle right now.

Cheers

animationtreeforum.png (30.6 kB)
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
1
Best Answer

Answer by ljdp · Apr 06, 2017 at 08:30 AM

You need to hold on to what's in the queue for longer. You have dequeue in FixedUpdate so you're queue will never get large enough to hold a combo. I recommend you have some sort of timer to remember how long ago the combo started.

 private float lastAttackTime = 0;
 private float comboTimeWindow= 0.5;
 void Update() {
   if(...) {
     lastAttackTime = Time.time;
   }
   if (Time.time > lastAttackTime + comboTimeWindow) {
     dequeue();
   }
 }
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

Mecanim RigidBody JUMP 0 Answers

Getting with the times... learning Mechanim/Animator 1 Answer

Mecanim animator layers 0 Answers

Changing speed of specific animation state, at runtime 1 Answer

Mecanim combo system occasionally stops and registers phantom clicks 0 Answers


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