- Home /
How to Reverse an equation.. (c#)
I have this equation:
float temproll = roll / 1.66666f; // Devide roll by 30
temproll = (temproll - 30.0f); // - 30
helirollSpeed = Mathf.Abs((temproll)); // Turn negative into positive
Which provides me a speed on this sale:
But now i need to reverse this for a rotation to speed conversion like this:
How would I go about this. Or how else could I turn rotation amount into a speed by this scale?
Sorry, I'm having trouble understanding what exactly you are trying to do. However, to invert a value simply subtract it from the maximum possible value it could have.
I'm trying to convert a rotation from 0 to 90, into a speed value. Where 0deg = 0 speed , 45deg = 30.0 speed and 90deg = 0 speed. Like the second scale image.
Answer by ArkaneX · Oct 10, 2013 at 10:23 AM
It's very similar to the response which @Hoeloe wrote as answer to one of your previous questions. Solution:
speed = 30 - Mathf.Abs((angle - 45) / 1.5f);
Description from Hoeloe's answer still apply, with the difference that you have to subtract the result from 30 to inverse speed.
You might want to consider studying up on simple mathematics - these are all just linear mathematical relations, and those are vitally important for any game's development.
I was referring to the OP, sorry. I meant it as an extension of this answer - I realise now that I didn't make this clear.
Answer by Nexum1 · Oct 10, 2013 at 10:24 AM
What you could do is create a public AnimationCurve In unity, set the animation so that at 0.5 (50%) the value is 30 and at 0 (0%) and 1 (100%) the value is 0.
Then get a percentage from the value you are trying to convert..
Value/90=Percentage
Then, get the value from the animation curve using that percentage.