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
1
Question by Endermansr · Dec 09, 2013 at 09:37 PM · mathf.lerp

Mathf.PingPong float values

This appears like it would be easy but it is racking my brain. What I am trying to do is use the skybox blender shader to transition between two different skyboxes. This I have working correctly. I have the skyboxes successfully transition when the float blend goes from 0 to 1. But I am having trouble with getting the float to, after it completes this initial transition, to then lerp back from 1 to 0. Here is an example of the script:

 public class DayNight : MonoBehaviour {
 
 public float blend;
 public Color daycolor = new Color (0.95f, 0.66f, 0.4f, 1.0f);
 public Color32 nightcolor = new Color (0.13f, 0.26f, 0.44f, 1.0f);
 
     
 void Start ()
     {
         RenderSettings.ambientLight = daycolor;
         
     }
     
 void Update () 
     {
         
     
         blend = Mathf.Lerp(0, 1, Time.time*.05f);
     
         RenderSettings.skybox.SetFloat("_Blend", blend);
         
         RenderSettings.ambientLight = Color.Lerp (daycolor, nightcolor , Time.time*.05f);
 
             
         
         
 }
 
 }

How do you use, or can you use, Mathf.PingPong to ping pong between float values? All I ever see is it using a vector3.

Thanks

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

Answer by robertbu · Dec 09, 2013 at 09:40 PM

Mathf.PingPong only does float values. So your code might look like:

  blend = Mathf.PingPont(1.0f, Time.time*.05f);

Might also consider using Sin() for a smoother transition:

 blend = (Mathf.Sin(Time.time * speed) + 1.0f) / 2.0f;

'speed' is a variable you define or a constant you insert.

Comment
Add comment · Show 3 · 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 Endermansr · Dec 09, 2013 at 10:27 PM 0
Share

Thanks for the quick reply. It is working correctly, the $$anonymous$$athf.Sin one, as far as what I want to happen except that I doesn't transition from 0 to 1, it stops about half way there. I have managed to have it transition from -1 to 1 but I need it to go from 0 to 1 and then back from 1 to 0. Any direction about how to do this?

Again, thanks.

avatar image Endermansr · Dec 09, 2013 at 10:31 PM 0
Share

Never $$anonymous$$d, I figured it out.

Thanks a lot for your help

avatar image frattapa · Oct 19, 2020 at 09:24 PM 0
Share

the second one worked perfectly in edit mode. Thank you!

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

17 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

Related Questions

Line drawing: How can I interpolate between points to create a smooth arc? 4 Answers

Why is the "t" value clamped to [0, 1] in Lerp functions? 3 Answers

Range repeat? like 50 to 100 then back to 50 1 Answer

Mathf.Lerp doesnt work well 1 Answer

ease in and out between blendshapes 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