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 qewo · Jul 24, 2013 at 06:42 PM · timetime.deltatimewhile

while coroutine not ending correctly using unityscript

Hi I'm making a door open and close using a transform instead of animation

 var speedTime : float;[1]
 private var t: float = 0;
 
 function Close() {
     
         stateOpen = false;
         stateClosing = true; // so we know its closing
         while (t < speedTime) {
             t += Time.deltaTime / speedTime; // sweeps from 0 to 1 in time seconds
             transform.position = Vector3.Lerp(initialEnd, initialStart, t); // set position proportional to t
             yield; // leave the routine and return here in the next frame
         }
     
         t = 0;
         stateClosing = false; // so we know its not closing
         stateClosed = true; // so we now its closed
     
     }

after closing the door i have to wait a prolonged ammount of time before i can open it again only if speedTime is over 1. it seems as if the while coroutine is waiting the length of speedTime until allowing itself to play again.

any help would be great I'm really stumped

[1]: /storage/temp/13481-door_slide.zip

door_slide.zip (680 B)
Comment
Add comment · Show 2
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 Eric5h5 · Jul 24, 2013 at 06:56 PM 0
Share

You can use basic debugging, such as putting Debug.Log("closed"); after the loop, to see what's happening. Also the t variable should be local to the Close function, not a global variable.

avatar image qewo · Jul 24, 2013 at 07:06 PM 0
Share

Thanks i have added speeTime to the open and close function, using the debug message yields the same results it takes a long time after t = speedTime to continue with the rest of the function.

1 Reply

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

Answer by Bunny83 · Jul 24, 2013 at 07:13 PM

You actually don't wait speedTime seconds but speedTime seconds squared

You divide Time.deltaTime by speedTime, so for example if speedTime is 5 it would take 5 seconds to reach 1.0. However your while condition checks for "t < speedTime". So it doesn't run 5 seconds but 25 seconds 5^2.

You want to use a while like this:

     while(t < 1.0f)
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 qewo · Jul 24, 2013 at 08:00 PM 0
Share

Awesome! Thanks works perfectly now :D

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Delaying through yield 2 Answers

Time Manager Class Implementation Like Coroutine in Unity 1 Answer

Is there a way to speed up the game more than 100 times? 1 Answer

Time does not start counting down when need to 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