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 emperor_guam · May 14, 2017 at 06:48 PM · c#animationcollision

User can jam on the attack button and get the player stuck in the attack animation.

0 down vote favorite

I am having a problem where the user can jam on the attack button and get the player character stuck on the last frame of the animation. In short my method for melee attack works like this.

Get input from the Player.CS then the script (animationController.CS) on the Animator attached to the Player sprite sees this and tells the Animator to use the attack animation. Then on the attack animation is an Animation Event that calls a function off of a key frame in the animation that spawns the collision object for the player's attack. When the collision object is destroyed the player is supposed to be allowed to attack again. But if the user presses attack too fast they player gets stuck at the last frame of the animation.

So my question is am I doing this wrong? Is this a bad method to deal with animations spawning the collision of a melee attack? Or have I screwed up the logic somewhere that I am just not seeing?

//This is in the Player.CS //If Player presses the attack button

    if (Input.GetKeyDown(KeyCode.X)  || Input.GetButtonDown("Attack") )
         {
                 //If we have not spawned the primary weapon and x has not already been pressed
                 if (!hasSpawnedPrimaryWeapon && !xPressedToAttack)
                 {
                     xPressedToAttack = true;
 
                 }
        }
 

// The above sends a message to the Player Sprite Animator.CS This does not do anything other than trigger the attack animation to play.

     if (playerScript.xPressedToAttack == true && playerScript.isDucking == false)
     {
         playerAttackingPrimary = true;
     } else playerAttackingPrimary = false;
 

//Later in the same script

     if (playerAttackingPrimary == true)
     {
         changeState(STATE_ATTACKINGPRIMARY);
     }
 

// Then using the animation event system when the attack animation is at the point of attack a function is called to spawn the primary weapon from the //Player Sprite Animator.CS

 public void isFinishedAttacking()
 {
 
     playerScript.spawnPrimaryWeapon();
 
 }
 

// Later the animation event system when the attack animation is finished a function is called to clear the xPressedToAttack flag // from the Player Sprite Animator.CS

 public void clearXandSpawnFlag() {
 
     playerScript.xPressedToAttack = false;
     Debug.Log("PrintEvent: setting xPressedToAttack to False at " + Time.time);
 
 }
 

// The spawnPrimaryWeapon() is located in the Player.CS.

 public void spawnPrimaryWeapon(){
 
     GameObject primaryWeapon = Instantiate(primaryAttack, PlayerHead.transform.position, Quaternion.identity) as GameObject;
     primaryWeapon.transform.parent = controller.transform;
     hasSpawnedPrimaryWeapon = true;
 
 }
 

// The PrimaryWeapon.CS works like this. When the lifetime is up it destroys it self. It sets the hasSpawnedPrimaryWeapon to false. The lifetime is a public int that is set to 7 when spawned.

 void Update () {
     lifeTime = lifeTime - 1;
 
     if (lifeTime <= 0){
         playerScript.timeOfAttack = Time.time;
 
 
         playerScript.hasSpawnedPrimaryWeapon = false;

         Destroy(gameObject);
     }
 
 }
 

// This is supposed to then allow the user to attack again but they seem to be able to attack again before this is complete. // If the user jams on the button the xPressedToAttack can become stuck on true and is then never set to false.

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

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

How can I animate a GameObject that isn't parented, but will need to be for the animation? 1 Answer

How to trigger an event if the collided object has the tag “Player” 3 Answers

chronological order of collision to give a winner unity 2d 4.3 1 Answer

How do I create two colliding Spheres? 1 Answer

Stop Root Motion if out of boundaries? Simple Wall Climbing System 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