 Hello guys, CryptoGround here. Welcome back to another Unity C-sharp idle game tutorial video. This episode 34 today We're not gonna be on Unity or me on the whiteboard instead because I feel like I should have explained and even learned myself How by max works and how we get the equations. So today I'm gonna show you how that works Okay, if you enjoyed the video, make sure you leave a like Subscribe to my channel and turn on those notifications for future videos and comment your suggestions below Anyways, let's get on with it So first our original cost equation come from something like this Okay, so we have our cost Equals base times R to the K next show we can change this K to something like L. So let's have a little Key right here. Okay. So we have B which is equal to the base or the start cost R is equal to the growth rate and L is equal to our current levels. Okay, so for example Let's say we want to set our cost equal to 100 times 1.5 L to the power of L Every time we have a level 100 will be multiplied by 1.5. So if level was 1, so if 100 times 1.5 to the power of 1 This is basically just 100 point or 100 times 1.5, which that will equal 150 as this example Hopefully that makes sense So this equation comes from something. It's very cool how it actually turns out. I'm gonna write this out So this is called the buy end cost. So basically any number N equals 2 is what the cost will be so our max is what we'll use to Calculate the maximum amount of upgrades we can use and we'll set that equal to N Okay, I'll show you after this. So what we do is that we multiply B times R to L which I've explained with these main over here and We multiply this by R times a new variable, which is N Minus one we're gonna divide this by R minus one. Okay You see these look very similar, right? Just hide this and you see this exact same equation So how do we get here? I'm about to show you So what we do is that this right here is the buy the buy one cost, right? So in here N equals to one in this situation, right? Here N is equal to N. Whatever we want it to be. Okay, so let's set N to one. Okay So now we have N equals one. There's something that we can do So whenever we have an exponent, it could be for example, e to the one or 10 to the one It'll always equal itself because it's multiplying itself one time So e to the one is simply e 10 to the one is simply 10 same thing here with R R to the one is just equal to R So now what we can do here is rewrite it as cost is equal to B times R the power of L Times R minus one now if you take an algebra or any class higher than that You should know what to do right now We can simply just get rid of these and or just replace these with one because R minus one divided by R minus one is equal to one So that becomes one over one So then we rewrite it as cost is equal to B times R over L and it's supposed to be R L times one over one But we can just simplify this to B times R L like that. Hopefully that makes sense It's really cool how this all came together now. You may not see this when you see this equation Originally, you may not see this but it's it's in there somewhere, right? So we actually get this equation from here not this equation from here, okay? So now we need to find what n equals how do we get n which in our case we want to do the maximum amount, okay? So in here, we'll write n equals right But I'm gonna get rid of this because we need to solve some math first because this is actually quite a little bit complicated So if you're in a lower level of math, this will look really confusing to you, okay? So if you've used by max in my methods, you can see that the equation for the count is C, right? So the thing here is that cost is C But when we are looking for what n equals C is also currency, okay? So what we're gonna do is that we're gonna replace this with C Okay Okay, so C is equal to b times r to the power of l times r to the power of n minus 1 and divide that by r minus 1 Okay, so now we need to make sure n is on the right side and everything else is on the left side, okay? So first things first we're gonna just start doing some multiplication and division So we're gonna get C on this side, okay? So we can divide b to get it over here. We can divide r over l to get it on this side So we then we know that if we divide these things to and put it on the other side we have C is divided by b times rl Okay, and this will equal to r n minus 1 over r minus 1 Okay, you may see things are starting to look kind of familiar to our bimax equation, right or our bimax count equation Okay So now we need to multiply r minus 1 to get it on the other side So we do see so we're gonna multiply r minus 1 from both sides. So we're gonna just see times r minus 1 divided by b times r over l and this is gonna equal r n minus 1 Our last step before we do some other fancy stuff to get rid of this r and we need to add 1 to both sides, okay? So this is gonna go this way So our C times r minus 1 Over b times r over k plus 1 is going to be equal to r over n also actually this should be l sorry also before we continue I'm gonna add n to our key, which is n is equal to number to buy Okay Now how are we gonna get this n equal to all of this? cool thing log Cool. So now what we do is that we log r both sides. Okay, so we do log r And we do log r Okay, and this will equal to log of r log base r and parentheses C times r minus 1 divided by b times r over l plus 1 is Equal to n because these two will cancel out Okay So we just do log base r on both sides and now we have our equation n is equal to the log base r C times r minus 1 over b times r to the power of l plus 1 and this is How many upgrades we can buy with the current cost or a current currency? Remember, this is currency owned very complicated. So take a look at this Okay, I'm going to replace this now I'm gonna write it up here. Okay, so the max upgrades to that we can afford right now is gonna be n is equal to log Based r inside that it's gonna be C times r minus 1 over b times r l plus 1 Like that now we have the plus one and pretty much every single log so that if inside this is zero log Any sort of log Long zero. This is does not exist and this is a big no-no and Caused a lot of problems. So we add this plus one Just to protect ourselves and Plus this plus one Remember this originally came from this one like that. Okay? So That is the math behind by maxes. I hope you guys understand this And if you have any questions, let me know in the comments below and I also just want to give you a heads up this only works if R is Constant the reason why is because when we calculate this right here It is calculating what r is equal to now right at that moment when this is being calculated If r is an equation, it's just gonna get what it's equal at that very moment. Okay? So remember it's only good for constants if you have for example Cost is equal to 100 times Let's just say 1.5 plus L divided by 100 To the power of L if you have something like this, this will not work. I Mean that you won't get any errors obviously, but this won't calculate correctly and you will get Cheaper cost than what it's actually equal to okay now doing an equation like this is very hard So just be sure try to avoid Something like this something good Something like C is equal to 100 times 1.5 to power of L Okay, I Hope you guys enjoy this video if you did make sure you smash the like subscribe to my channel and comment your suggestions below and All your questions there too. Check out my videos in this top corner right here Thank you guys for watching and hope you guys have a good day or night. Peace