I would do it in Mecanim for sure- this is a perfect example of where Mecanim really shines, provided that you have the pivot set up as a joint properly beforehand. Give the turret a Body Mask so that this “animation” only affects the top half above the joint, save a 1 frame “animation” of it being at the minimum height and a 1 frame “animation” of it being at maximum height, then make a sub state machine on a second layer (using the Mask, not additive, layer weight 1) in which the level of blending between one or the other is dependent on a pitch variable 0-1 float that you feed it from your scripts.
That’s just for the pitch, and is only an example- there are likely a dozen ways to do this.
While the idea sounds viable, converting the calculated angles to mecanim animation frames sounds messy and inaccurate.
Code can be found about halfway down (one of my posts). If it doesn’t work correctly, make sure all your default rotations are 0,0,0. Can tell you it works 100% of the time every time.
There’s no real reason why you’d have to set up a conversion to 0f-1f float values, that’s just my personal preference to keep mecanim looking clean internally. If you have a min and max angle in mind, you can set those as the state machine’s minimum and maximum parameter thresholds directly in mecanim (making single-frame animations for the two different “states” that match those angles), and then simply feed the angle into SetFloat without converting it at all.
Also, your mention of “mecanim animation frames” sounds like you might be misunderstanding my intention a bit- I didn’t mean to make some sort of a “pivot range” animation then deciding which frame = which angle and using that frame as the transition point. In my solution, there’s exactly 1 frame in two “still-frame” animations in a 2-part sub-state-machine- one that’s completely down as far as it goes, and one that’s as high as it goes. Just those 2 frames, in two different “states”. The angle would be decided entirely based on a transition percentage between “minimum threshold” and “maximum threshold”, which, if you set the min and max thresholds to match the visible angle of the pivot in the still-frames, means you can be completely accurate simply feeding the desired angle into mecanim directly (I think).
I admit I’ve never actually done this, but I don’t see anything wrong with the theory, and although it sounds complicated, it’s all just gibberish for “just do it and it’ll work”. =)
Indeed, I agree, and I wasn’t trying to imply that my mecanim method was superior, though I do think it would mesh better with compound animation transitions (which is a mostly-moot point for a model that has a single ball-and-socket joint anyways). I just don’t like leaving misconceptions in threads- for posterity, more than anything, though I’m sure pride plays a role too.