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
2
Question by runevision · Nov 05, 2009 at 01:18 PM · curveanimationcurvekeyframetangent

How can I set the tangents of Keyframes in an AnimationCurve through scripting?

I want to set both tangents of a Keyframe in an AnimationCurve through scripting, just like it is possible to do in the Animation view in Unity. How can I do it in code?

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

Answer by runevision · Nov 05, 2009 at 01:25 PM

If you have an AnimationCurve called myAnimationCurve, you can get a Keyframe from this curve and set the tangents of that Keyframe like this:

// Get the fourth key in the curve Keyframe key = myAnimationCurve[3];

// Set both tangents to something key.inTangent = 1; key.outTangent = 0;

// Put the modified key back into the curve myAnimationCurve.MoveKey(3, key);

You can also smooth out the tangents of a Keyframe by using SmoothTangents on the AnimationCurve:

// Smooth the tangents of the fourth key in the curve
myAnimationCurve.SmoothTangents(3, 0);

The second parameter, weight, controls the contribution of the two tangents in the smoothed result. -1 makes the smooth result equal to what the inTangent was before; 1 makes it equal to what the outTangent was, and 0 produces an average.

Comment
Add comment · Show 2 · 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 vyruz · Sep 02, 2010 at 04:36 AM 0
Share

can i use myAnimationCurve.keys[3].inTangent = 1 directly?? and can you plz explain the SmoothTangents i just cant get it does it take only 0,-1,1??? thxxx

avatar image runevision ♦♦ · Sep 02, 2010 at 01:03 PM 0
Share

No you can't set myAnimationCurve.keys[3].inTangent directly since it would just modify a struct which is never assigned back into the curve. SmoothTangents takes a float that can be anything in between -1 and 1.

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

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

What is the length of the Keyframe tangent? 0 Answers

Extending tangents in Animation window 0 Answers

How do I scale an animation curve by time and value while retaining my tangent values? 0 Answers

Tangents ignored while setting keyframes 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