Let's say I have a turret and a target like the ones shown bellow. How do I calculate rotation angle I need to rotate the turret around y axis for it to start hitting the target and the angle at which it becomes rotated too much and stops hitting the target. Keep in mind that the cannon is not placed in the center of the turret.
Ok typically if the cannon was in line with the pivot point of the turret you could use The Quaternion.LookAt function to determine the desired Rotation. However, with this offset turret you are going to need to add an additional offset angle. The magnitude of this angle is going to depend on both how far way the target is from the pivot point and how far offset the turret is from the pivot(measured along an axis perpendicular to direction the turret is pointing). Anyway if you divide the turret offset by the distance you will get the tangent of the angle you need. You can use this to calculate the additional rotation to add. An example:
answered Feb 26 '12 at 02:25 AM