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 /
  • Help Room /
avatar image
0
Question by MobinYaqoob · May 26, 2016 at 02:41 PM · yieldcoroutinesasyncwhile-loop

Condition implementation Problem

Just take this example :

 void Start ()
     {
         StartCoroutine("TriggerCubeAnimation");
     }


  IEnumerator TriggerCubeAnimation()
     {
         foreach (var o in cubes)
         {
           while (o.transform.position.y<fMaxLimit)
             {
                 o.transform.Translate(v3speed.x * Time.deltaTime, v3speed.y * Time.deltaTime , v3speed.z * Time.deltaTime);
                 Debug.Log(v3speed.x*Time.deltaTime + "  " + v3speed.y*Time.deltaTime + "  " + v3speed.z*Time.deltaTime);
                 yield return null;
             }
         }
        yield return new WaitForSeconds(1.0f); 
     }



I have Four Cubes in Row what i want is when my first cube start animation and when it reached at position 3.0f at Y-axix then the other cube start its animation all four cubes reached at 3.0Y in a row . like first then second then third and then fourth. and it does. But problem start when i want to make it faster if i make v3speed.y a big value it over reached the while condition and give some thing weired values.

for example : if fMaxLimit is 3.0f. then if i make v3speed.y = 20.0f the v3speed.y increses 20 per/sec and

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 MobinYaqoob · May 26, 2016 at 02:43 PM 0
Share

the cube not stops of 3.0 they always stop like 3.22225 , 3.125654 , 3.56565848 Some thing greater than 3.0

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JedBeryll · May 26, 2016 at 07:34 PM

If you give it large steps like that it will of course overshoot, you never tell it to stop at 3. for example an iteration calculates v3speed.y * Time.deltaTime which is let's say 0.524f, and v3speed.y was already at 2.9f it will be 3.424. If you want to keep it from overshooting you can clamp it's magnitude with Mathf.clamp, or calculate the next value without assigning it and check if it is larger than the fMaxLimit. If it's larger then just make it equal fMaxLimit. Otherwise Translate it.

Comment
Add comment · 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

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

59 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

Related Questions

Coroutine doesn't continue after yield another coroutine 0 Answers

Coroutine or While loop that you can reset/add time too? 0 Answers

NEED HELP PLEASE: When i kill a one of the three limited "mobSpawned" the "while (true)" don't work and don't spawn a new object. Anyone have a solution for this. Thanks. 1 Answer

Designing a dialogbox that displays message, returns a custom object and waits for user response 0 Answers

Failing a UnityTest when a condition that's expect to change in given amount of time doesn't? 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