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 asimov · Jul 10, 2012 at 08:12 PM · animationtranslatecrossfade

How to stop animated character returning to starting position after animation is complete

Hi,

I'm animating an intro to a level where my Player starts off standing on a box and then jumps off and begins a running stance. I will CrossFade a running animation and a translation forwards to move him and begin the game.

Now, to ensure that the animations are not looping, they are all set to WrapMode.Once and the loop is activated using a key press.

The problem I'm having is that while I can successfully CrossFade the animation from Standing on the box -> Jumping off of box onto ground and beginning to run, the Player always seems to return to his starting position on the box after this. The running animation that follows this then takes place at this starting position, and if I also translate him forward, it will occur at that elevated height.

I'm wondering how to get around this, do I have to reset his position or something similar?

Thanks

//-- Continuing from comments below;

     void Start () 
         {  
             // PLAYER
             PlayerObj.animation[Player_start_idle.name].wrapMode = WrapMode.Once;
             PlayerObj.animation[Player_start_escape.name].wrapMode = WrapMode.Once; // Tried; ClampForever, Clamp
             PlayerObj.animation[Player_run.name].wrapMode = WrapMode.Loop;
             
             // Also tried adding the run animation into a higher layer
             //PlayerObj.animation[Player_run.name].layer = 2;
         }
     
        void update()
        {
            StartCoroutine(PlayEscapeAnimations());
        }
 
   IEnumerator PlayEscapeAnimations()
       {
           PlayerObj.animation.CrossFade(Player_start_escape.name, 0.2f);
 
           yield return new WaitForSeconds(Escape_lights_delay);
 
           if (PlayerObj.animation.IsPlaying(Player_start_escape.name))
           //PlayerObj.animation.CrossFade(Player_run.name, 0.2f);
           {
               // Let this animation finish
           }
           else
           {
               PlayerObj.animation.Play(Player_run.name);
           }
       }


 
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Yoerick · Jul 11, 2012 at 09:11 AM

In my eyes, this could be because of 1 of these 2 things:

  • You don't apply gravity to your object, or you don't translate it's y position. So your character will not fall down but stays at the height it starts at.

  • Your animation might be wrong. Did you change the character's position animation wise? Like, when he jumps, the character's y position changes in the animation itself? Because you need to change the y position of the character gameObject, not the animation. In the animation itself, your character's position should remain more or less the same.

    Explanation: the character model has a prefab, which turns into a gameObject when you place it in your game. This gameObject has a certain position in the world. An animation is played, relatively to this point as it is a child/component of this gameObject. When you reposition the character inside the jump animation it will look like it moves but the parent gameObject doesn't change position, only the mesh itself. When you then return to the running animation, which probably has no position offset, it will play this animation relatively to the position of the gameObject again, which didn't move. Resulting in your character swapping back to it's starting position. At least, that's what seems to happen.

I hope this answer doesn't confuse you too much, if it does I'm sorry but I don't think I can explain it any better.

Hope it helps ;)

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 asimov · Jul 11, 2012 at 08:40 PM 0
Share

Thanks for the suggestion,

I've now modified it so that the Y position doesn't change.

Now at the end of the jumping animation, the run animation that I try to CrossFade in doesn't start at all. The Player just freezes.

I tried $$anonymous$$ike's suggestion too and used Wrap$$anonymous$$ode.ClampForever and this freezes the animation at the end too. In fact it's also freezing/stopping when I use Wrap$$anonymous$$ode.Once.

I'll paste the script above, hopefully you can spot what going wrong.

Thanks

avatar image Yoerick · Jul 12, 2012 at 11:14 AM 0
Share

When looking at your code, it seems logical he only plays the "escape" animation as you're calling the coroutine every single frame (in Update) and the first thing this coroutine does, is play the escape animation.

So I think the if statement in the coroutine never gets to the "else" part? Because when the compiler comes to "if (PlayerObj.animation.IsPlaying(Player_start_escape.name))" it will always be true, as you just started the animation 2 lines before that if statement.

avatar image Yoerick · Jul 12, 2012 at 11:27 AM 0
Share

I posted a new answer to be able to post the code that I think it should be ;)

avatar image asimov · Jul 17, 2012 at 12:27 PM 0
Share

Hi,

I have now resolved this problem. It was initially an issue with the Y-position as you mentioned, Yoerick. So animated the jumping on the Player without the change in the Y-position and used Unity's animation tool to create the arc to the lower Y-position. The latter issue was one involving the structure of an if-else statement.

$$anonymous$$any Thanks to everyone for their suggestions. The ClampForever suggestion by whydoidoit, also came in handy :)

avatar image
0

Answer by whydoidoit · Jul 11, 2012 at 09:16 AM

You want to use WrapMode.ClampForever to stop it from automatically resetting to the starting frame.

Comment
Add comment · Show 2 · 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 asimov · Jul 11, 2012 at 08:56 PM 0
Share

Hi $$anonymous$$ike, thanks for the suggestion, please see the comment above.

avatar image whydoidoit · Jul 12, 2012 at 04:49 AM 0
Share

How annoying! Perhaps try testing that the animation.normalizedTime is = 1 to see if the sequence is complete with ClampForever?

avatar image
0

Answer by Yoerick · Jul 12, 2012 at 11:23 AM

I adjusted your script so it doesn't always trigger the escape animation in the coroutine. I'm not sure about what the "`Escape_lights_delay`" is supposed to do but I assume it's some sort of delay you apply after the escape animation?

What did I change? I put the escape animation in the Start function as I understand it needs to play immediately? Now the coroutine is still called every frame but doesn't start an animation by default. It just checks if the escape animation is playing and if not, start the run animation after the "`Escape_lights_delay`". Is this kinda what you're looking for?

 void Start () 
         {  
             // PLAYER
             PlayerObj.animation[Player_start_idle.name].wrapMode = WrapMode.Once;
             PlayerObj.animation[Player_start_escape.name].wrapMode = WrapMode.Once; // Tried; ClampForever, Clamp
             PlayerObj.animation[Player_run.name].wrapMode = WrapMode.Loop;
 
             //start the escape animation at the beginning
             PlayerObj.animation.CrossFade(Player_start_escape.name, 0.2f);
  
         }
 
        void update()
        {
            StartCoroutine(PlayEscapeAnimations());
        }
 
   IEnumerator PlayEscapeAnimations()
       {
           //PlayerObj.animation.CrossFade(Player_start_escape.name, 0.2f);   -> deleted because otherwise, this animation will always be playing
 
           if (PlayerObj.animation.IsPlaying(Player_start_escape.name))
           {
               // Let this animation finish
           }
           else
           {
               yield return new WaitForSeconds(Escape_lights_delay);
               PlayerObj.animation.Play(Player_run.name);
           }
       }
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

6 People are following this question.

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

Related Questions

Problem with animations, How to blend them?? 0 Answers

Animation.Play blends previous animation 1 Answer

Animation.CrossFade help please 3 Answers

CrossFade to Specific Animation Time (Coordinate Animations) 1 Answer

Animation.CrossFade Lag 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