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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by rooted · Nov 20, 2013 at 08:22 AM · triggermathf.sin

Arbitrary starting value for Mathf.Sin? How to start it at 0? Now with video example! :)

Should I use another Mathf??

How would you "smoothly" trigger an oscillation of a variable to start at zero upon entering a trigger, then continue to oscillate [Mathf.Sin(Time.time)*x] until trigger exit, then smoothly return to zero, all at a definable rate?

===>video example

 This is what I have so far but doesn't seem to work right , I'm a newbie:

     var minimumTwirl = 0;
     var maximumTwirl = 12;
     
     private var originalAngle: float = 0;
     private var tTwirlIn: float = 1.0;
     private var tTwirlOut: float = 1.0;
     private var duration: float;
     private var trip = false;
     
     
     
     function Start(){
         var Twirl: TwirlEffect = Camera.main.GetComponent(TwirlEffect);
         Twirl.angle = 0;
         
     }
     
     function Update (){
         var Twirl: TwirlEffect = Camera.main.GetComponent(TwirlEffect);
         var current = Twirl.angle;
     
         
         if (tTwirlIn < 1.0 && trip == true) { // attempting to smooth if value other than zero
             tTwirlIn += Time.deltaTime/duration;
             Twirl.angle = Mathf.Lerp(current, minimumTwirl, tTwirlIn);
     }
     
         if (trip == true && tTwirlIn > 1){ //start oscillation of value
             
             Twirl.angle = Mathf.Sin(Time.time)*15;
 }
 
         if (tTwirlOut < 1.0 && trip == false) { //this works surprisingly well!??
         
         tTwirlOut += Time.deltaTime/duration;
         Twirl.angle = Mathf.Lerp(current, minimumTwirl, tTwirlOut);
 }        
 


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
0

Answer by karljj1 · Nov 20, 2013 at 09:11 AM

A coroutine would be an idea.

Something like this:

OnTriggerEnter starts the coroutine. OnTriggerExit sets a flag to indicate it should lerp back to zero and then quit the coroutine.

Your cotroutine would look something like this:

 while( exit Flag Is Not Set )
 {
 do the oscillation for one frame
 yield return 0; // Wait for the next frame
 }
 
 // Lerp back to zero
 while( its not zero )
 {
 MoveTowards zero.
 yield return 0; // Wait for the next frame
 }

Karl

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 rooted · Nov 20, 2013 at 09:55 AM 0
Share

Thanks for your reply. I attempted to script what I'm trying to do. This is what I have so far but the Twirl.angle functions don't work perfect yet. I posted the code above.

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

Can't click gameobject when over another trigger? 1 Answer

Increase Speed 1 Answer

Trigger and Collider Issues 1 Answer

OnTriggerStay still called after moving a parent gameobject 0 Answers

Possible to make OnMouseOver ignore triggers? 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