Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 AKJ9 · Aug 30, 2014 at 03:36 PM · c#animationgameobjectpositionupdate

Update character's position after animation

Hi there,

I have a character who can perform some basic attacks. If a key is pressed, he'll swipe his sword, if the same key is pressed within a few milliseconds after that first swipe, he'll perform a second swipe. Finally, if the same key is pressed again for a third and final time after that second swipe, he'll perform a spinning strike. So I basically have a combo going on here.

The problem is, after the third swipe, my character moves position, but then reverts back to his old position after the animation. Now I've read that this has to do with the player's mesh moving, but not the gameObject itself. I just can't figure out a solution of how to update his position after the strike. Here's a snippet of my code that focuses on the attacks:

 if (Input.GetKeyDown (KeyCode.B) && firstSlash == false && secondSlash == false && SwordCollect.swordObtained == true && blocking == false && attacking==false && HealthController.flinch==false) {
                                 blocking = false;
                                 StartCoroutine (attack ());
             } else if (Input.GetKeyDown (KeyCode.B) && firstSlash == true && attacking==false && HealthController.flinch==false) {
                                 blocking = false;
                                 StartCoroutine (attack2 ());
             } else if (Input.GetKeyDown (KeyCode.B) && secondSlash == true && attacking==false && HealthController.flinch==false) {
                                 blocking = false;
                                 StartCoroutine (attack3 ());
 
 IEnumerator attack (){
         attacking  = true;
         animation.CrossFade ("slash",0.2f);
         audio.PlayOneShot(slash1);
         yield return new WaitForSeconds (animation ["slash"].length);
         attacking = false;
         firstSlash = true;
         yield return new WaitForSeconds (0.2f);
         firstSlash = false;    
     }
     IEnumerator attack2 (){
         attacking  = true;
         animation.CrossFade ("slash2",0.2f);
         audio.PlayOneShot(slash2);
         yield return new WaitForSeconds (animation ["slash2"].length);
         attacking = false;
         secondSlash = true;
         yield return new WaitForSeconds (0.2f);
         secondSlash = false;    
     }
     IEnumerator attack3 (){
         attacking  = true;
         animation.CrossFade ("slash3",0.2f);
         audio.PlayOneShot(slash3);
         yield return new WaitForSeconds (animation ["slash3"].length);
         attacking = false;
     }

Any help or advice would be much appreciated.

Thanks in advance.

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 BMayne · Aug 31, 2014 at 04:30 AM

Hey There,

This is a problem with the animation itself. If you moved the game object to correct the position it would just move the animation the same amount. The animation just moves the vertices in the mesh based on a offset from the GameObject.

You can do two things

1) Fix the animation

2) Blend between the end of the third attack and the starting idle animation.

Comment
Add comment · Show 1 · 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 AKJ9 · Aug 31, 2014 at 09:45 AM 0
Share

@B$$anonymous$$ayne thanks for your response. How would I go about fixing the animation? What if I want the animation to move my game object forward and not just in one position?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

C# Trouble getting object's current position on mouse down. 0 Answers

Trigger LateUpdate on inactive gameObjects 2 Answers

adding animation dynamically by script 0 Answers

Play audio.PlayOneShot() once in an Update() function 2 Answers

Check if player object is right above this object 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