- Home /
 
               Question by 
               ctd25 · Oct 28, 2014 at 04:08 AM · 
                c#rotationquaternionturret  
              
 
              Turret Continuing to Max Rotation - Following Mouse Cursor
I have a turret in 3d space that follows the mouse cursor - the base rotates on the x axis, turret rotates on the y.
When the mouse goes past a pre-defined max-angle, the turret stops rotating. I can't figure out a way for it to continue rotating up to the max angle and then stop.
This is what I'm using to rotate the turret:
barrelStart is a quaternion indicating the original rotation of the barrel
barrel is a quaternion indicating the rotation of the barrel to look at the mouse
 if (Quaternion.Angle(barrelStart, barrel) <= maxGunAngle)
                 gun.localRotation = Quaternion.RotateTowards(gun.localRotation, barrel, gunDegreesPerSecond * Time.deltaTime);
Is there a better way to clamp the rotation beyond the If condition I'm using? Or is there a way to calculate what the rotation should be to get to the max angle?
Hope this is clear.. Pretty new to unity. Thanks in advance.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                