normalize two angles, then modify the result?
This is tricky for me. I need a solution for something that I know requires a math-heavy approach. I struggle with mathematics in coding. I don't know how to even word the question properly, so if this has been asked before then I was unable to find an answer by searching (due to not knowing quite what I'm looking for).
I need to rotate a machine gun that is housed in the front of a tank. Our input is going to be two separate floats, one for X, one for Y from -1 to +1. The rotation needs to be limited to 45 degrees each extent (left to right, up and down). If the X input is -1 then the gun is rotated all the way to the left (for example. These bits might not be accurate as I type as it depends on the orientation of the object. But let's say it's correct for now). If the X input is 1 then the gun is all the way to the right. If it's 0, it's dead ahead. The equivalent is true for the up/down movement.
I don't need any lerping really as the inputs are coming from physical hardware which is hard setting the two floats as it's moved.
So what I think I need is a way of converting the input to an angle that I can feed into the asset to make it change the way it points. Or the other way round. Not sure. Some way of normalizing the angle to a range between -1 and 1, and then feed the input into that?
If anyone can point me in the right direction I'd appreciate it, and if this has been asked before (by someone who knows the right terms!) then I'll happily delete this question.
Thanks, Mike
Wait, so you're asking how to convert -1 to 1 into -45 to 45?
... yes, I think so... that sounds like it would work. I have a feeling you're about to tell me that there's a super simple bit of maths for this.