I’m having a brain meltdown trying to figure out how this works. I have an object that will move along one axis depending on the angle of another object.
The start position of the object’s axis is 5.9, and the max value it needs to get to is 7. The object rotating will start at 0 degrees and will reach a max of 160 which should move the object to 7.
I can’t figure out a way to add to the axis based on the angle of the object be rotated. Anyone have an idea how to do this?
I’m not a math professional, but I would figure you’d want to get the percent that your rotation is at (so if it’s at angle 25, what percent of 160 is 25) and then use that value to Lerp or movetowards the other object. Since the third value is decimal version of percent, I would think this would work.
If you’re trying to scale a result from a range of 5.9 - 7… into a range of 0 - 160 then this will work.
/// <summary>
/// <para>Remaps a Value from number Range A (Value, OriginalMin and OriginalMax) to number Range B (MinAllowed, MaxAllowed)</para>
/// </summary>
/// <param name="unscaledNum">The raw data value.</param>
/// <param name="originalMin">(Range A) The value's original range minimum.</param>
/// <param name="originalMax">(Range A) The value's original range maximum.</param>
/// <param name="minAllowed">(Range B) The minimum goal value.</param>
/// <param name="maxAllowed">(Range B) The maximum goal value.</param>
/// <returns>The remapped/scaled value.</returns>
public static float Scale(float unscaledNum, float originalMin, float originalMax, float minAllowed, float maxAllowed)
{
return (maxAllowed - minAllowed) * (unscaledNum - originalMin) / (originalMax - originalMin) + minAllowed;
}