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
0
Question by BestSwter · Apr 04, 2015 at 03:15 PM · timechangedecimal

Make a change every 0.02 seconds precise

I want to make something to change it's position every 0.020 seconds and after it finishes one cycle, speed it up to 0.019 and so on. I tried working with decimal but still not precise enough. Please help ^^

Comment
Add comment · Show 4
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 Scribe · Apr 04, 2015 at 04:01 PM 0
Share

you can change its position within the system every 0.02 seconds, however how you actually view its position changing will be dependent on the frame rate of the computer, could you expand on why you are trying to do this!?

avatar image tanoshimi · Apr 04, 2015 at 04:32 PM 0
Share

It's not possible to guarantee ti$$anonymous$$g of execution of any function at that level of precision. Perhaps if you explain why you're trying to do this we can suggest alternative approaches.

avatar image Owen-Reynolds · Apr 04, 2015 at 04:45 PM 0
Share

I think what works better is to think in terms of speed/second. To increase the speed, increase the speed (ins$$anonymous$$d of decreasing the time unit, keeping speed constant.)

If you have integer movement, round the "use me" value to the nearest. If you move 40 times during a 60-frame second, it will be in 20 positions for 1 frame, and 20 positions for 2 frames. But there is no way to avoid that.

avatar image Scribe · Apr 06, 2015 at 11:28 AM 0
Share

@tanoshimi calling InvokeRepeating("SomeFunction", 0, 0.02f);

with:

 void SomeFunction(){
     Debug.Log(Time.time);
 }

prints exactly 0.02, 0.04, 0.06 etc...

is this 'faked' somehow or how does it happen to be exact.

I also tried:

 IEnumerator SomeFunction(){
     while(true){
         Debug.Log(Time.time);
         yield return new WaitForSeconds(0.02f);
     }
 }

and sure enough it is way out with what time the function calls itself

Can you explain this? :O

Thanks,

Scribe :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ozturkcompany · Apr 04, 2015 at 03:22 PM

I do think its not possible but i suggest you looking at how Time.deltaTime increase by time. Create a variable and set it to something like;

 private var a : float = 0;
 
 function Update()
 {
     a += Time.deltaTime;
     Print(a);
 }

See how a value increases per frame, then you might have to see the chance whether it is possible to detect that small amount of change in seconds. Cheers.

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 ozturkcompany · Apr 04, 2015 at 03:32 PM 1
Share

Hmmm, i think that i have found you a possible solution. Why won't you look at your system's time? You can read system's time and it's miliseconds. 1000 miliseconds is 1 sec. So it might be handy for your case.

avatar image BestSwter · Apr 04, 2015 at 03:45 PM 0
Share

An Update takes 0.016 aprox each frame to take and a fixedupdate taxes 0.02 seconds each frame. I was thinking that maybe the global times is measured in 0.1 miliseconds, dunno :(

avatar image ozturkcompany · Apr 04, 2015 at 03:47 PM 1
Share

I think that it is worth to shot to try System's time and use it's miliseconds

avatar image ozturkcompany · Apr 04, 2015 at 04:36 PM 1
Share
 #pragma strict
 private var t : float = 0;
 
 function Update ()
 {
     CompareValues ();
 }
 
 function CompareValues ()
 {
     t += Time.deltaTime;
     Debug.Log(t);
     if($$anonymous$$athf.Approximately(t, 0.02))//O$$anonymous$$, we got the value!
     {
         Debug.Log("YES!" + ", Difference is: " + (t - Time.deltaTime));
     }
     if(t > 0.02)//OH, we missed it...BUT let's say we got the value since it will be pretty to close to what we want!
     {
         Debug.Log("YES!" + ", Difference is: " + (Time.deltaTime - t));
         t = 0;
     }
 }

This is the closest you can get...Sadly it is not possible. alt text

lskdmk.jpg (225.2 kB)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to smootlhy change values in amout of time? 3 Answers

Shrink and change color of GUI 0 Answers

Unity seems to be taking a long time destroying a scene? 0 Answers

Color lerp once? 2 Answers

Changing / Adding Material over Real-World Time 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