Rotating from a percentage

I’m trying to rotate an arrow to point at the right point on this meter. Unfortunately, the maximum value (when the arrow is pointing like it is in the image) is -140 degrees and the min value (when the arrow is pointing the opposite direction) is 45 degrees. The problem I am having is I can’t figure out how to get past 0 degrees when using a percentage. For example, when I want the meter to be 100% full I want it to be at -140 degrees and when its 0% full I want it to be at 45 degrees. (I know this is terribly explained, but I don’t know how to explain it much better than this.)

image

If anyone has any wisdom they would like to send my way, I will be rather grateful.

This is a fantastic use case for lerp. What you want to do is linearly interpolate between a value of 45 and -140, based on a percentage. Try something like this!

newAngle = Mathf.Lerp(45, -140, myPercentage)
2 Likes

thank you so much! this was what i needed!

Glad to hear it! If you have any issues with lerp going the long way around, LerpAngle might be the better option, since it supports rotating the shortest distance around, so for example lerping from 300 to -10 would just rotate the value to 370