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 /
  • Help Room /
avatar image
1
Question by denizhd21 · Oct 24, 2021 at 01:41 PM · lerptime.deltatimecolor.lerp

Time.deltaTime getting faster each time

In my project, I want to change the color of the background in the game with Color.Lerp function. In update I made a "if"and wrote this in it:

 slowMode = true;           
 kamera.GetComponent<Camera>().backgroundColor = Color.Lerp(normal, slow, c);
 c += Time.deltaTime;

This one is working fine at the start. It just takes 1 second to lerp. fine as I said.

But when I wanted to change back to the "normal" color from "slow" it takes lesser than 1 second it takes like 0.4 seconds. I am using this code this is supposed to get back to the normal color in 1 second.

kamera.GetComponent().backgroundColor = Color.Lerp(normal, kamera.GetComponent().backgroundColor, c); c -= Time.deltaTime;

How can I fix this?

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

Answer by TheMemorius · Oct 24, 2021 at 02:19 PM

In the first lerp between normal and slow, you got two unchanging values that you lerp in between. This produces the effect you want: Linear interpolation between two values. But when you move in the other direction, you're lerping between a fixed value (`normal`) and the current background color, which is a value that is changing each frame. So the range that you're moving across is shrinking while you're moving across it, which distorts the movement and gives you a curved rather than a linear movement.

(It should still take 1 second to reach the target value, but you'll reach a value very close to that target in a much shorter time, making it look like everything is just sped up.)

What you need is a lerp between two values that don't change - so don't use the changing background value as a parameter to the lerp function. The easiest fix would be to use your slow variable instead:

 kamera.GetComponent().backgroundColor = Color.Lerp(normal, slow, c);
 c -= Time.deltaTime;
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 denizhd21 · Oct 24, 2021 at 05:45 PM 0
Share

Thank you, I did it kamera.GetComponent().backgroundColor = Color.Lerp(normal, kamera.GetComponent().backgroundColor, c); c -= Time.deltaTime;

this way because there was another thing changing the background color. When both were used in a few seconds, background color was just going crazy a little bit, since it is a low possibility to these background changers get used together, in a few seconds... the other one is more important and more possible for a player to see.

I will use your solution.

avatar image
0

Answer by EvilBob99 · Oct 26, 2021 at 09:17 AM

would it not be possible to put this in fixed update I'm not to sure on this because im still pretty bad at programming

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

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

Healthbar color lerp between green, yellow, and red 4 Answers

How to animate fog color over time for day night cycle 1 Answer

Why Mathf.Lerp dosen t work correct? 1 Answer

Light intensity Lerp not functioning properly 1 Answer

Time.DeltaTime Bug 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