Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Ripple · Jun 15, 2015 at 05:43 AM · lerplayerweight

How do I smoothly shift between Layer Weights

I'm trying to shift between my character's default layer to another layer where his arms are masked smoothly so it looks like putting them out to hold a gun.

 public bool gun;
 
     void Update () {
         if (gun) {
             animator.SetLayerWeight (GunLayer, Mathf.Lerp (0.0f, 1.0f, Time.time));
         }
     }

Whenever gun is true I want the Layer Weight to lerp from 0 to 1 but it instantly goes to 1 if it is in a if condition block. When I take it out the if condition block it works perfectly but for my game I need to use an if condition.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Vazili_KZ · May 09, 2020 at 04:31 PM

For anyone still reading this.

I just want to add that using "Mathf.SmoothDamp" can result in an even smoother transition since you have more control over how that transition behaves for ex: how long is it supposed to last

Down here is an example of how i used it. I suggest you refer to the doc here for more info


 var m_currentLayerWeight = _playerAnimator.GetLayerWeight(1);
     m_currentLayerWeight =Mathf.SmoothDamp(m_currentLayerWeight, IsArmed ? 1 : 0, ref _currentLayerWeightVelocity, animTransSmoothTime);
     _playerAnimator.SetLayerWeight(1,m_currentLayerWeight);


PS : in this example we fade in & out depending on if the player IsArmed or not

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
0

Answer by Nicola Castellani · Nov 22, 2015 at 05:45 PM

You could just use a variable for saving the current layer weight:

Fade Out:

currentWeight = Mathf.Lerp(currentWeight,0.0f,Time.deltaTime); anim.SetLayerWeight(1, currentWeight);

Fade In:

currentWeight = Mathf.Lerp(currentWeight,1.0f,Time.deltaTime); anim.SetLayerWeight(1, currentWeight);

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation Controller not returning character to correct position. 0 Answers

Animation: Impact of combining the use of Layer, CrossFade, and Weight 2 Answers

What am I not getting about animation weight blending? 4 Answers

Play 2 animations at once 4 Answers

streaming layerweight onserializeview 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