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 infinitypbr · Jun 25, 2013 at 08:36 PM · animatormecanim

Mecanim: Backward animations only work in preview, not in game

Hello,

I have a blend tree that works fine when the enemy is set to be moving forward, but when going backward, the legs do not move. The preview for the Animator component shows the character (model and all) moving backward when I slide the "speed" toggle to less than zero, but when the game is running, and the speed is set to less than zero, the legs simply stand still.

The character is being controlled by a navmesh, with the speed and angular speed being passed to mecanim to display the proper animations.

Any idea why this may be breaking during game?

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
0
Best Answer

Answer by infinitypbr · Jun 26, 2013 at 06:04 AM

Ok, let it never be said that I'm not an idiot a lot of the times.

"Loop Pose" wasn't checked.

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
avatar image
0

Answer by DecipherOne · Jun 25, 2013 at 11:03 PM

I would check and see if there is a bounds restriction in a part of your code that will not let the animation play backwards at runtime.

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 infinitypbr · Jun 26, 2013 at 12:03 AM 0
Share

I'm not sure what you mean by bounds restrictions, but I haven't written any restrictions or anything.

avatar image
0

Answer by TonyLi · Jun 26, 2013 at 12:30 AM

I think @DecipherOne is talking about something in your code that's preventing the speed parameter from being set to a negative number.

For example, NavMeshAgents don't walk backwards; they turn instead. The speed is never going to be less than zero.

When the game is running, select the enemy and look at the Animator window. Make sure the value of the speed parameter is what you expect.

Comment
Add comment · Show 5 · 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 DecipherOne · Jun 26, 2013 at 12:41 AM 0
Share

Yep, @TonyLi that's exactly what I was saying. Check and make sure there isn't a bit of code somewhere that keeps your speed from being negative when you're actually running the game.

avatar image infinitypbr · Jun 26, 2013 at 12:43 AM 0
Share

Ah, yes, I see the negative value in the animator during runtime, exactly as expected. Here's the code I use, with a little segment that checks to see if the direction the object is traveling in is the same direction it's facing or not. If they're facing the wrong way, I make the movement speed negative.

 var positionDistance = Vector3.Distance(enemyLastPosition, transform.position);
         var movementSpeed = (positionDistance * (1 / Time.deltaTime));
         
         var facingDifference = Vector3.Distance(enemyLastPosition, Vector3(transform.position.x, transform.position.y, transform.position.z + 1));
         
         // FIND OUT IF ENE$$anonymous$$Y IS WAL$$anonymous$$ING BAC$$anonymous$$WARD -- Facing opposite direction they're walking
         if (facingDifference > 1)
         {
             movementSpeed = movementSpeed * -1;
         }
         print ("movementSpeed: " + movementSpeed);
         enemyAnimator.SetFloat ("Speed", movementSpeed);
avatar image DecipherOne · Jun 26, 2013 at 01:01 AM 0
Share

I found this after a quick search. I'm not really familiar with mecanim myself, but this http://forum.unity3d.com/threads/167951-$$anonymous$$ecanim-Use-Case-play-animation-from-any-frame-forward-or-reverse thread suggest that sort of functionality isn't available through mecanim currently.

avatar image TonyLi · Jun 26, 2013 at 01:29 AM 0
Share

That's a good thought from @DecipherOne. But since you can preview it in the editor, you must be using a separate animation for retreating (or at least another copy of the animation with Speed=-1). So that should work fine.

Sounds like an issue with the animation state machine. That's where I'd check -- make sure it's transitioning properly into the blend tree, and that the blend tree is using the parameter values in the way you're expecting.

avatar image infinitypbr · Jun 26, 2013 at 05:46 AM 0
Share

Yeah, right now all the animations are in one 2d blend, and I think I'll try to make two blends, one for forward and one for back, with an "isBackward" variable or something.

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

17 People are following this question.

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

Related Questions

Animator state not activating immediately.(URGENT) 0 Answers

Animation Impulse System? 1 Answer

Getting the position of an object in an AnimationClip ? 1 Answer

Mecanim Combo Tree returning to Idle State 1 Answer

Using Ragdoll on character with mecanim animator 2 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