Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 oskar-s · Jan 04 at 10:36 AM · coroutinetimespeedtime.deltatimeturn-based

RPG Action Progress Bar always same speed

Hello, I make an RPG with turn based combat where the turn ordere is calculated based on the character speed. A Coroutine checks if a character is ready. If no character is ready it increases all characters Action Progress bar by a value ( different for each char) and starts the coroutine again as long as no character is ready for action. My Problem is now that i wanted to test it and every time i start the play mode, the action bars recharge at a different speed. I think its because of framerate and other stuff going on. but this will be a problem with different devices as some people will wait longer than other. Tried to solve this with Time.deltaTime but its not exactly working. Can someone have a look on my Code?

 IEnumerator WaitForCharactersReady()
     {
 
         float tickTime = 0.02f;
 
         if (readyCharacters.Count == 0)
         {
             for (int i = 0; i < playerTeamControllers.Length; i++)
             {
                 playerTeamControllers[i].characterStats.IncreaseActionProgressByOneTick();
                 playerSpotUis[i].SetActionBar((int)playerTeamControllers[i].characterStats.actionProgress);
                 if (playerTeamControllers[i].characterStats.isReadyForAction())
                 {
                     readyCharacters.Add(enemyTeamControllers[i]);
                 }
 
             }
             for (int i = 0; i < enemyTeamControllers.Length; i++)
             {
                 enemyTeamControllers[i].characterStats.IncreaseActionProgressByOneTick();
                 enemySpotUis[i].SetActionBar((int)enemyTeamControllers[i].characterStats.actionProgress);
                 if (enemyTeamControllers[i].characterStats.isReadyForAction())
                 {
                     readyCharacters.Add(enemyTeamControllers[i]);
                 }
             }
             while(tickTime >= 0.0f)
             {
                 tickTime -= Time.deltaTime;
                 yield return null;
 
             }
         
             StartCoroutine(WaitForCharactersReady());
         }
     }
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
0

Answer by s4shrish · Jan 04 at 06:09 PM

Hi, I don't understand your in-game logic, but I can help with the coroutine stuff.

You can try using "yield return new WaitForSeconds()" to wait a specific amount of time.

But alternatively I would recommend you using "yield return new WaitForFixedUpdate();". It will run alongside FixedUpdate for 50 times a second. That should solve your issue of different characters incrementing by variable amount.

That said, regardless of the way the coroutine is running, it should increase all character ticktime evenly, so my guess is that IncreaseActionProgressByOneTick(); has some issues as well.

If I would have to do something similar, I would do it somewhat like below

IEnumerator ActionCoro() { while (!gameOver)//Or just true { if(readyCharacters.Count <= 0) { for () { //go through all the player characters } for () { //go through all the enemy characters } } yield return new WaitForFixedUpdate(); } }

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

145 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 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

How do I increase a speed variable over time? 1 Answer

Time Manager Class Implementation Like Coroutine in Unity 1 Answer

Accelerate/Decelerate Custom Game Clock 2 Answers

Returning an IEnumerator as an int? 1 Answer

Speed = 11 meters /s plane is 110 meters should take me 10 seconds but it dosn't 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