Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sylon87 · Jun 19, 2019 at 01:11 PM · velocitymathf.sinsin

Using Sine Wave to control time

hello! i have my object that is moving in a sin wave with mathf function, that is this

 float t = currentLerpTime / lerpTime;
 t = Mathf.Sin(t * Mathf.PI * 0.5f);

i want something that start fast and finish slower so i think that the sine wave is what i'm looking for but i don't really know how to manipulate it to get what i looking for.. any help?

what i exactly want is something like this but without using AnimationCurve alt text

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 metalted · Jun 19, 2019 at 01:49 PM

You can change the amplitude and period of a sine wave. The following page shows you how to change the period: https://www.dummies.com/education/math/trigonometry/adjusting-the-period-of-a-sine-function/ The amplitude of the sine wave is simple a multiplication of the outcome of the Sin calculation.


So as you show with the curve in the picture, you are looking for a logarithmic curve. Using the following formula will get you there: Vc = V * (1- e^(-t / R*C)).

  1. Vc = Value on the curve after t-seconds

  2. V = Maximum value of the graph (so 1.0)

  3. e = constant (2.71...)

  4. t = time in seconds

  5. R*C / TAU = not really important what it means but you can control the curve with it. If you enter 1 here the curve will take 5 seconds to go from 0% to 100%, if you enter 2 here it will take twice as long.


In C# this formula will be:

 float maxValue = 1.0f;
 float timer = 1.0f // This is a timer or counter or something
 float tauValue = 1.0f;
 float value = maxValue * (1 - Mathf.Pow( (float) Math.E, (-timer / tauValue));
 
 //I couldn't find E in the Mathf class so I had to add the System namespace to have Math.E



 //This will be the code making use of the Mathf.Exp() function suggested by Bunny83
   
 float maxValue = 1.0f;
 float timer = 1.0f // This is a timer or counter or something
 float tauValue = 1.0f;
 float value = maxValue * (1 - Mathf.Exp(-timer/tauValue));
 

 Some examples:
 R*C = 1
 t=1        Vc=0.63
 t=2        Vc=0.86
 t=3        Vc=0.95
 t=4        Vc=0.98
 t=5        Vc=0.99
 
 R*C = 2
 t=1       Vc=0.39
 t=2       Vc=0.63
 t=3       Vc=0.77
 t=4       Vc=0.86
 t=5       Vc=0.91
 t=6       Vc=0.95
 t=7       Vc=0.96
 t=8       Vc=0.98
 t=9       Vc=0.98
 t=10     Vc=0.99




Comment
Add comment · Show 4 · 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 Sylon87 · Jun 19, 2019 at 02:17 PM 0
Share

Hello! thank's you for your help! i updated my question to be more clear

avatar image metalted Sylon87 · Jun 19, 2019 at 08:20 PM 0
Share

The curve you are showing here is a curve from a logarithm. I use this curve in my field to calculate the discharge and charge times of a capacitor. We use the following formula for that:


Vc = V * (1- e^(-t / R*C))


So little explanation: Vc is the value after t-seconds. V is de full value, so in your case that will be 1 (0.0 - 1.0). e is the natural log and is a constant (2.71....). t is the time in seconds and R*C is the value that deter$$anonymous$$es the curve. In electronics this is mostly replaced by TAU which is a charge characteristic. The curve is always the same when you just replace the TAU (R*C), only the time is different. So the curve is always (for us) counted in TAU's. 1TAU will be 63%, 2TAU will be 81%, 3TAU will be 86% .... 5TAU will be 99%. 5TAU is in most cases seen as 100%.


So if I got it right, if you replace R*C / TAU with a 1, the curve will be 5 seconds, but I'm not exactly sure about that anymore.

avatar image Bunny83 · Jun 19, 2019 at 10:07 PM 1
Share

You know that the FPU inside your CPU has a specialized method for calculating e^x? Specifically

$$anonymous$$athf.Exp

avatar image Sylon87 · Jun 19, 2019 at 11:27 PM 0
Share

Thank's you i'll learn it...for now that's is working well... thank's 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

108 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

Related Questions

Using sin and cos to decompose a vector 2 Answers

Velocity powered rigidbody on a moving platform without parenting. 3 Answers

Rotating emitter direction whilst maintaining particle velocity 1 Answer

Rigidbody - Applying One-Time Force? Not Constant Force 2 Answers

A ball drops down, how to reverse the velocity? 2 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