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 DevMerlin · Feb 24, 2016 at 06:05 PM · c#mathfmathf.lerp

Using Blend Trees, I want to switch smoothly based on input, but my input is simulated. How can I achieve this?

I've seen this topic discussed a few times before, but no one really seems to provide a solid answer to it. Here's my own take and problem: I've got three control states - (-1, 0, 1). -1 is backwards, 0 is idle, and 1 is forward.

Initially, I just used a direct button press. Down = 1, up equaled -1, and states between caused idle to occur. That required somewhat of a complex animation tree, with ineffectual smoothing between animation states.

Now, I have started using Blend trees - however, direct switching between the three states causes abrupt animation changes. I'd like to smooth that out, but I'm not sure of the best way to do so.

This is what I have come up with so far:

 private void PlayerControlSystem()
 {
     if (ControlKeysPressed)
     {

         ControlSwitch = Mathf.Lerp(ControlSwitch, 1, 0.1f * Time.deltaTime);
     }
     else
     {
         ControlSwitch = Mathf.Lerp(ControlSwitch, -1, 0.1f * Time.deltaTime);
     }
 }

It partially works, but has some problems such as when it hits zero it should idle, but keeps trying to walk/run as the value itself is actually 0.4456457f (to infinity). I'd like to create a quick and smooth tween between animations instead and it properly stops when the controls are at correct values.

How can I accomplish this?

Comment
Add comment · Show 1
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 DevMerlin · Feb 24, 2016 at 06:46 PM 0
Share

I've discovered part of the problem. It's never actually reaching zero, despite the states in the tree being -1, 0, and 1 itself. I tried switching it around and using the built-in lerp, as well as assigning all positive values, but the problem still persists even with this:

     if (ControlSwitch == 0)
     {
         _anim.SetFloat(_animHashes.$$anonymous$$ovement, 0, .35f, Time.deltaTime * 2);
     }

     if (ControlSwitch == 1)
     {
         _anim.SetFloat(_animHashes.$$anonymous$$ovement, 1, .35f, Time.deltaTime * 2);
     }

     if (ControlSwitch == -1)
     {
         _anim.SetFloat(_animHashes.$$anonymous$$ovement, 2, .35f, Time.deltaTime * 2);
     }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Zoogyburger · Feb 24, 2016 at 06:15 PM

So you have an animation controller for your player and have a transition between Idle and Walking. Click on that transition and in the Inspector the will be settings. Grab and drag the blue bar on the timeline all the way to 0:00. If that doesn't work, uncheck Has Exit Time.

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 DevMerlin · Feb 24, 2016 at 06:25 PM 0
Share

No offense, but I think you completely misunderstood the question. I'm already using an animation controller, and I have a blend tree set up to handle the walking animation variants. I don't want abrupt changes that unchecking 'has exit time' would create.

avatar image
0

Answer by DevMerlin · Feb 24, 2016 at 06:55 PM

Got it! Okay, so I was on the right track, but I had to add in some additional locks to prevent undesired movement beyond some basic conditions. Essentially, I had one method that was overriding the others, even though it appeared to be 0 it was just changing to fast for me to see.

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

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

Related Questions

Mathf.Lerp supposed to be in Update()? 2 Answers

Multiple Cars not working 1 Answer

Mathf.Lerp not working, why? 1 Answer

Distribute terrain in zones 3 Answers

how to use time on lerp 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