Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 Ultroman · Dec 12, 2018 at 09:59 PM · timespawnrandomization

Spawn chance, modulated by probability weighted by progress

I've been struggling with this for over a day now. What seemed a simple task, has just wrecked me. I hope someone here can help me figure out what I'm missing. Please, please help me :)


The functionality I need:

Think of my game as Guitar Hero, but instead of pre-placed nodes, I place the nodes randomly as the game progresses, at certain valid points in time. Now, instead of relying on randomness alone, I've made phases of difficulty, where I set a certain number of nodes to be spawned throughout the phase, and I'd like to have those evenly distributed within the phase. Since it's an arcade/highscore game, it needs to be roughly the same number of nodes placed every time you play the game, but the nodes should be placed differently each time. Until recently, I simply had something like this:

 if(Random.Range(0f, 1f) < 0.25)
     // Spawn node



The problem:

Now I want to balance the number of nodes per phase. To do this, I have these variables:

  • TotalNodesToPut

  • NodesPut

  • NodesLeftToPut

  • PhaseProgress (0.0-1.0 normalized percentage of progress)


My plan was, to have the base chance of spawning a node to be 50%, and then modulate that down to 0% and up to 100% depending on how many nodes still need to be put down, and how far we have progressed through the phase. It should be so that the percentage of nodes put down follows the progress percentage. So I thought this would do the trick:

 if(Random.Range(0f, 1f) < 0.5f + ((PhaseProgress - (NodesLeftToPut / TotalNodesToPut)) - 0.5f))

But, to take a simple example, where we're halfway through the phase, and have placed half the nodes, so we should end up with 0.5:

 0.5f + ((0.5 - (10/20)) - 0.5f) = 0

This is only one of the hundreds of different ways I've tried and failed. I thought I had it dozens of times, but then something went wrong at the end or beginning of the phase, or the modulation percentage was way too low or something.

It seems like a simple task, but I just can't get it to work :( I have tried searching on the web, but haven't found anything about this particular problem. Any help is much appreciated!

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

2 Replies

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

Answer by Ultroman · Dec 16, 2018 at 12:35 AM

We finally figured it out, and it WAS a super simple problem, which I was over-complicating, and I was missing the fact that I had to account for the difference being above or below 0.

This swings between 0 and 1, and you can set whatever base chance you want, for when pointsPut is the same as estimatedPointsPut.

 var baseChance = 0.3f;
 if (pointsPut <= estimatedPointsPut)
 {
     modularChance = 1 - ((float) pointsPut / estimatedPointsPut);
 }
 else
 {
     modularChance = ((float) estimatedPointsPut / pointsPut) - 1f;
 }
 modularChance *= 1 - baseChance;
 modularChance += baseChance;
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 Wolfride · Dec 16, 2018 at 02:36 AM 0
Share

I'm that sad artist who could only answer you if you were using Playmaker. But I COULD answer you. If you use Playmaker. LOL Thanks for posting your figured-it-out!

avatar image
0

Answer by Browntown90 · Dec 12, 2018 at 10:53 PM

Still trying to wrap my head around this, but the math in your example doesn't really make sense.

 >PhaseProgress == NodesLeftToPut/TotalNodesToPut So,
 
 PhaseProgress - (NodesLeftToPut/TotalNodesToPut) == PhaseProgress - PhaseProgress == 0
 
 > 0.5f + (PhaseProgress - (NodesLeftToPut/TotalNodesToPut)) - .5f
 
 0.5f + (PhaseProgress - (NodesLeftToPut/TotalNodesToPut)) - .5f
 
 0.5f + (0) - .5f = 0


No matter what, you'd end up with 0.

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 Ultroman · Dec 12, 2018 at 11:15 PM 0
Share

You seem to have the parentheses wrong. The last -0.5 is part of the larger parenthesis. If you have put 5 nodes, but need to put 20, so you've put 0.25 of them, and have made it 0.75 of the progress, you would get 0.25. Well, this was really just the last thing I tried. I've been through this thing countless times. If you have more questions I'd be more than happy to clarify things.

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

100 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

Related Questions

Why are my bullets shooting at an unpredictable rate? 3 Answers

random enemy spawn from day night cycle 2 Answers

More Efficient Enemy Spawning Than This? 2 Answers

how do i make my spawn system spawn every 2 seconds then wait 10minutes? 3 Answers

spawn timer problem 2 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