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 Inan-Evin · Apr 18, 2015 at 07:00 PM · smoothkeysframestangent

Scripting Curves, How To Maintain The Shape ?

Hello guys, I have a little problem. I am trying to learn how to script AnimationCurves, in order to change my Color Correction Curves Image Effect in runtime. I've figured out the most of it, but still I have a minor glitch to solve. First, here is the default value and the desired value of my red channel :

alt text

So I wrote this script:

 using UnityEngine;
 using System.Collections;
 using UnityStandardAssets.ImageEffects;
 
 public class IS_ActionImageEffects : MonoBehaviour {
 
     public Transform t_EffectsHolder;
     public float f_LerpSpeedRed;
     public float f_LerpSpeedRedBack;
     public bool b_WaitFirst;
     public float f_WaitFirst;
     public float f_WaitToLerpBack;
     private ColorCorrectionCurves _CorrectionCurves;
     private Vector2 v2_OriginalRedKey;
 
     void Awake()
     {
         _CorrectionCurves = t_EffectsHolder.GetComponent<ColorCorrectionCurves>();
     }
 
     void OnEnable()
     {
         
         StartCoroutine(LerpRedChannel());
 
         
     }
     
     IEnumerator LerpRedChannel()
     {
         if (b_WaitFirst)
             yield return new WaitForSeconds(f_WaitFirst);
 
         float i = 0.0f;
         float rate = 1.0f / f_LerpSpeedRed;
         float f_CurrentTime = _CorrectionCurves.redChannel.keys[1].time;
         float f_CurrentValue = _CorrectionCurves.redChannel.keys[1].value;
         v2_OriginalRedKey.x = f_CurrentTime;
         v2_OriginalRedKey.y = f_CurrentValue;
         float f_KeyTime;
         float f_KeyValue;
 
         while (i < 1.0f)
         {
             i += Time.deltaTime * rate;
             f_KeyTime = Mathf.Lerp(f_CurrentTime, 0.6f, i);
             f_KeyValue = Mathf.Lerp(f_CurrentValue, 0.3f, i);
             _CorrectionCurves.redChannel.MoveKey(1, new Keyframe(f_KeyTime, f_KeyValue));
             _CorrectionCurves.redChannel.SmoothTangents(1, 1);
             _CorrectionCurves.UpdateParameters();
             yield return null;
         }
 
         yield return new WaitForSeconds(f_WaitToLerpBack);
 
         i = 0.0f;
         float rate2 = 1.0f / f_LerpSpeedRedBack;
         float f_CurrentTime2 = _CorrectionCurves.redChannel.keys[1].time;
         float f_CurrentValue2 = _CorrectionCurves.redChannel.keys[1].value;
 
         while (i < 1.0f)
         {
             i += Time.deltaTime * rate2;
             f_KeyTime = Mathf.Lerp(f_CurrentTime2, v2_OriginalRedKey.x, i);
             f_KeyValue = Mathf.Lerp(f_CurrentValue2, v2_OriginalRedKey.y, i);
             _CorrectionCurves.redChannel.MoveKey(1, new Keyframe(f_KeyTime, f_KeyValue));
             _CorrectionCurves.redChannel.SmoothTangents(1, 1);
             _CorrectionCurves.UpdateParameters();
             yield return null;
         }
 
     }
 }

Which lerps 2 values in order to make the change smooth, waits, and lerps those values back. But the problem is, curves get, lets say, broken. I can't maintain the shape, here is the visual of the curve after the first while loop and after the second one :

alt text

It seems like something to do with my tries to maintain the things by using SmoothTangent, but I've tried:

 SmoothTangent(1,0);
 SmoothTangent(1,0.5f);
 SmoothTangent(1,1);

I've got slightly different results but none of them helped me solve the issue. So, what am I missing? Thanks in advance :)

attach1.png (14.1 kB)
attach2.png (18.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

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

Problem of creating smooth animations 3 Answers

smoothness parameter slider problem 0 Answers

How to get a smoothed Icosphere procedurally 1 Answer

Mecanim control animation frames via script? 2 Answers

How to access camera preview frames with MediaCapture Class in Unity? 0 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