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 /
avatar image
0
Question by sharmajeenit2000 · Jan 28, 2019 at 02:21 PM · levelwaitforsecondscoroutinesenemy aispawning-enemies

How to gradually increase difficulty.

Hey, I wanted to know a way to increase difficulty of game, gradually with time. I am using coroutines to spawn enemy ships, and I decrease the wait for seconds time as the game goes on to ramp up difficulty. But, if someone plays exceptionally well and survives for more than 5 minutes, there are crazy amount of enemies spawning, resulting in crashing of game. So can someone just give me the logic to control the game difficulty. BTW GAME IS ENDLESS RUNNER SORT OF.

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
1
Best Answer

Answer by RadonRaph · Jan 29, 2019 at 09:10 AM

Hello, you could use a math fonction like Mathf.sqrt(Time.deltaTime/1000); This number will progress slowly with time.

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 sharmajeenit2000 · Feb 02, 2019 at 10:53 AM 0
Share

@WhiteCry should i use the above mentioned func. inside waitforseconds. But, then that means that the no. of enemies spawning decreases(as time interval between each one is increasing) with time, implying difficulty decreases with time.

So, can you please elaborate the above mentioned code a bit.

avatar image RadonRaph sharmajeenit2000 · Feb 02, 2019 at 11:26 AM 1
Share

I don't know how you spawn your enemies so i can't do math without value. I think you can try something like this public float spawnDelay; public float difficultyFactor = 60; // Use this for initialization void Start () { StartCoroutine(spawnEnemies()); } IEnumerator spawnEnemies() { int nbEnemies = $$anonymous$$athf.RoundToInt($$anonymous$$athf.Sqrt(Time.time / difficultyFactor)); for (int i = 0; i < nbEnemies; i++) { //SPAWN YOUR ENE$$anonymous$$IE } yield return new WaitForSeconds(spawnDelay); StartCoroutine(spawnEnemies()); }

By default i have set a factor to 60 that means the curve will be: https://puu.sh/CG6fx/a2b23d673a.png The x axis is the time in seconds and the y axis is the number of enemies. So at 5$$anonymous$$ every spawndelay 2 enemies spawn. You can multiply the nbEnemies to accelerate the spawn Raph

avatar image RadonRaph RadonRaph · Feb 02, 2019 at 11:44 AM 1
Share

$$anonymous$$ore clearly code: https://pastebin.com/A36qr492

Show more comments

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

102 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

Related Questions

Using coroutines to do attack patterns 1 Answer

Can specified frames of an audio track trigger events? 0 Answers

Trying to implement synchronized laser system. 1 Answer

Mysteries of yield 1 Answer

Javascript function with coroutine fails when called from C# 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