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 /
  • Help Room /
avatar image
1
Question by TimNick151297 · May 27, 2016 at 08:31 PM · animationanimatorfloatblendtree

Create Idle/Walk/Run Blendtree

Hey there,

I' m trying to setup the blendtree in mecanim for hours now. I just want a simple fade between the motions "Idle", "Walk" and "Run", if left shift is pressed. Currently my blendtree looks like this: alt text

I don't know how to set the float properly for the transition from idle to walk and then from walking to running.

Thanks for your help!

img.png (56.1 kB)
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 Jessespike · May 27, 2016 at 08:38 PM

The BlendTree needs the float to be set between 0 and 1. So in your character controller script, lerp the float to 0 when Shift is not pressed, and lerp the float to 1 when shift is pressed.

Holding shift to move around is uncommon. Usually you would use Input.GetAxis or something relative like the velocity of the character to set the float. Especially for movement blendtrees that require different states, idle, walk, and run. Not sure how you plan on differentiating between walk and run, when shift can only be either pressed or not.

Maybe something like this:

 Animator animator;
 float speed = 0f;

 // Update is called once per frame
 void Update () {

     if (animator == null) animator = GetComponent<Animator>();

     if (Input.GetKey(KeyCode.LeftShift))
     {
         speed += Time.deltaTime;
     }
     else
     {
         speed -= Time.deltaTime;
     }
     speed = Mathf.Clamp(speed, 0f, 1f);

     animator.SetFloat("Speed", speed);
 }

I think the tutorials explain all of this in a better way: https://unity3d.com/learn/tutorials/topics/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 TimNick151297 · May 29, 2016 at 10:13 AM 0
Share

First of all, thanks for your answer! Currently I'm indeed using Input.GetAxis to set the float. It's 0 when there's no input from vertical or horizontal axis and it is increasing to 1 the other way around. $$anonymous$$y problem is now the transition to "run". I'd like to smoothly blend between walk and run when left shift is held down. If the user releases the button, the animation should blend back to walk.

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

97 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 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 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 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 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 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

Animation sinks player into the ground 1 Answer

How to prevent colliders animating between animation states? Also prevent rotation on x axis of blend tree. 0 Answers

How do I modify animation parameters from script (C#) 1 Answer

Animator Position VS Script Vector 3 0 Answers

Why isn't my animation looping? 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