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 MountDoomTeam · Oct 18, 2012 at 06:13 PM · errorupdatedelaytime.time

Time.time button delay trick causing NaN

EDIT-I solved this, the processor was receiving extra lines of code performing transform positions etc while a time delay variable was waiting for Time.time to catch up, the actual code that was supposed to hold was being ignored, I don't know why, but I found the solution was setting Time.time to 0.

hello, I have a number of key presses to Dig tunnels, and I have made a small code to make the digger dig automatically with emulated key presses- it all works fine except in the case where I have narrow tunnels only one block wide, where there is an error related to time delay:

If the lastFire key-delay variable is very small likes 0.1 seconds, the digger jumps by 100 spaces at a time and flies off into space like -7000 in a couple of seconds, and it completely ignores a)the last fire timing restriction and b) it multiplies the next space calculation by a lot.

If the lastFire key-delay variable is very larger likes 0.5 seconds, it jumps by 1000 spaces at a time and flies off into space like -800,000/Infinity/NaN in a couple of seconds, and it ignores the last fire timing restriction, it is clearly digging dozens of space is a second instead of two, and jumping to 1000 metres away instead of just 1.

If it digs narrow tunnels one block wide and uses keyboard keys instead of automatic dig navigation variable, no errors.

Here's the code-

 function Update ()
 {   
 if ( Input.GetKeyDown("x")){//increment x and flip on /off with %2
  automaticDigging += 1; 
  pressedKeys = 0;
 }    
     if ( automaticDigging%2== 1){//automatic digging 0/1 is on
 print( " rndc" + rndc  );
     if (pressedKeys % randomSteps == 0)//sets random number of key presses in succession to press one key for and when it has completed that number, chooses another random number(randomSteps ) and a random key to press (randomKey)
     {randomSteps = Random.Range (2, 10);
     randomKey = Random.Range (1, 7);//choose one of six directions
         }
     }
     else{rndc=0;}//automatic digging is off

 //if key is pressed or a key emulator variable (randomKey)found:
     if ( (Input.GetKey("l") || randomKey == 1 )&& Wt==1 && Time.time > lastFire)
     {
     lastFire = Time.time + fireRate;
     mov = stp1;
     DigNavigate (tree,1,burrowLength);
     m=m+1;  pressedKeys = pressedKeys + 1;
     }
 if ( (Input.GetKey("j") || randomKey == 2...// etc same for other digging keys ijkl


The larger tunnels dig automatically fine because they take more processing time and it prevents the above loop from interrupting itself or messng up the Time.time variable.

Comment
Add comment · Show 1
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 MountDoomTeam · Oct 18, 2012 at 06:50 PM 0
Share

the if condition seems to be ignoring the Time.time restriction and putting extra lines of commands into the processor while it waits for Time.time to complete, I found the solution! Just putting Time-delay between keys to 0 makes it runs fine, when the key is emulated by a variable.

0 Replies

· Add your reply
  • Sort: 

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mecanim 1 frame delay [solved] 2 Answers

[HELP!!] Files all missing while I update the version from Unity 2018.3.12f1 to Unity 2019.1.4f1 0 Answers

Unity 2020.2 crashes when loading my Unity 2020.1 project 0 Answers

Tutorial button doesn't work 0 Answers

Update() cannot be a coroutine 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