- Home /
increase a certain ratio value
hello guys
on my game i have a player input from 0 to 1 based on mouse y axis.
to score i have to get 2 point, so it should go from 0 to 1 and go back, for the next score the variable in this case i'll call
float _score;
i have to increase it by a constant of 1.2f, so it will be 2.4 (2 * 1.2) then with mathf.floor i get an int of 2, so i want to create an algorithm that take the floor throwed 0.4f then add it to the constant of 1.2, so i'll get an constant of 1.6 on the next time that player scored, so it's are going to be harder
i can't figure out how to do it (mathematically)
not sure i understand the question. you want the up and down mouse position to create a number from 0 to 2 from top to bottom of screen????
then get a $$anonymous$$imum of 1.2? added 1.2 multiplied 1.2? rounded to 1.2?
if you can explain what and why you are doing this we can provide and answer for you
Yeah, I'm not sure I understand your description either. Can you clarify where these numbers are co$$anonymous$$g from and why you're using $$anonymous$$ath.Floor for rounding?
Answer by Sylon87 · Aug 25, 2018 at 04:43 AM
ok well itàs a game where i have to cut a stuff that i have on front of the camera, to simulate a °cut° iàm using the mouse y axis for the movement, it go from 0 to 1 range ( i modified it myself), for cut the first stuff i have to make 2 complete cut so from 0 to 1 = 1, the go back from 1 to 0 = 2, now let me name do an example
float _cut'; float _numofCut = 2;
if ( cut > numofCut) { //do stuff }
after the first cut i want to increase _numofCut by a ratio of 1.2, then round it with floor by do (_numofCut 1.2) that should give me back again 2 and throw the 0.4, what i want is an algorrithm that add this 0.4 to the variable _constant that in my case for the next step will be multiplied as this (_numofCut 1.6) and so on.
for make it more easy to understand let me assign a value of 1.2 to a variable
float _ constant = 1.2f;
i hope that now it's more clear.
Answer by Em3rgency · Aug 25, 2018 at 07:22 AM
Sorry, it's still hard to understand what you want exactly. But I tried my best. Would this work?
private float GetNextModifier(float lastModifier, int numOfCut)
{
float modifiedCut = numOfCut * lastModifier;
float remainder = modifiedCut - mathf.floor(modifiedCut);
return lastModifier + remainder;
}
private void Update()
{
float _constant = 1.2f;
int numOfCut = 2;
if(cut > numOfCut)
{
//do something
_constant = GetNextModifier(_constant, numOfCut);
numOfCut = numOfCut * _constant;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
ScriptableObject Drop-Down Menu with added variables? 1 Answer
Why is my ID value getting stuck here? 1 Answer
How can i scale a ui Panel from the left side only ? 2 Answers