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 Orolo · May 14, 2016 at 05:24 PM · animationmecanimspeedfeet

Automatically adjusting the speed of a walking animation to avoid foot-sliding?

My most recent attempt looks like this:

 var animVel = Vector3.Project(m_Animator.velocity, m_Rigidbody.velocity.normalized);
 Debug.DrawRay(transform.position, animVel * 50f);
 float animSpeed = animVel.magnitude;
 if (animSpeed > 0f) {
     m_Animator.SetFloat("Forward", m_Rigidbody.velocity.magnitude / animSpeed);
 }
 else
 {
      m_Animator.SetFloat("Forward", 1f);
 }

Which may well be nonsense, but it's been an improvement. :] "Forward" is used as a parameter for the speed multiplier in the animator controller.

Anyway, how would one go about doing this?

Also, what's the difference between animator.velocity and animator.deltaPosition?

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
1

Answer by Multithreaded_Games · Feb 16, 2017 at 01:58 PM

@Orolo,

The easiest way to do this is to use root motion. Assuming you are using a humanoid rig, I'd have a look at and override the Animator.OnAnimatorMove function. This function will be called during each update frame or physics tick (depending on what your animation update mode is set to.)

Within this function, you'll want to read out either deltaPosition (this is the root-motion driven 'translation' of your character) or the velocity (this is pretty much the same as deltaPosition but it hasn't been multiplied by deltaTime). I would guess that the distinction is mostly for standard translation versus Rigidbody updates--for translation, deltaPosition is already what you want, but if you want to use it with Rigidbodies, you'll want to divide by deltaTime. Similarly, if you want to use velocity with translated bodies, you'll want to multiply by deltaTime. I can elaborate on this more if necessary

Basically you'll be using controller/keyboard/mouse or whatever input to set your animator parameter values. The deltaPosition returned within OnAnimatorMove is directly related to how much the root motion position changes (for humanoids, this is already defined for you as a special node) and this is related to what parameter values you set to 'drive' the animation.

One last caveat: for your particular walk/run animations, you'll want to NOT bake the XZ translation into the pose itself, otherwise OnAnimatorMove updates will return no velocity change for the deltaPosition/velocity. I would suggest setting up a test scene using the Unity standard ThirdPersonController (ethan model) to get all of this working correctly, and you might want to have a look at that code as well, although I'm not sure exactly if it uses OnAnimatorMove updates.

This is probably a lot of information, but let me know if anything is unclear and I'll try to help as best I can!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

mecanim animation runs at random speed on iOS 0 Answers

Mecanim - changing animation clip speed, through script? 4 Answers

Mecanim problem with setting speed 0 Answers

Are mecanim blend trees linear? 2 Answers

Mecanim animator. Set speed of a single clip. 3 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