Quantcast
Channel: Answers for "Turret Rotation on a moving object with rotation limits"
Viewing all articles
Browse latest Browse all 6

Answer by sevensixtytwo

$
0
0
You can use just one segment of code from robertbu's answer. Here: var toTarget : Quaternion = Quaternion.LookRotation(target.position - turret.position, turret.up); transform.rotation = Quaternion.RotateTowards(transform.rotation, toTarget, turretSpeed * Time.deltaTime); //freeze Z-axis to stop turret from rolling transform.localRotation.z = Quaternion.identity.z; With these alone, the turret will rotate towards the target on all axes, except Z. Use the ClampAngle function specified in aldonaletto's answer here: [Limit Local Rotation][1] It automatically converts negative values into usable eulers. Of course, you'll need minimum and maximum values for your X and Y axes. Use it like this: var angleX = ClampAngle(turret.localEulerAngles.y,minX,maxX); var angleY = ClampAngle(turret.localEulerAngles.x,minY,maxY); turret.localEulerAngles = new Vector3(angleY,angleX,turret.localEulerAngles.z); [1]: http://answers.unity3d.com/questions/141775/limit-local-rotation.html

Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>