• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

I tried to make a box to select units like you do in windows 1 Answer

How to keep a Gameobject in the same position after a transform.Rotate? 2 Answers

Animation not at correct position W/Video 0 Answers

Simultaneously moving GameObjects using C# script. 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges