Rotation of a turret on a moving ship, and picking targets within limited x,y,z rotation angles

Hello Unity Answers,

I’m trying to set up turrets on my spaceship, and when I try to think through the rotations my brain overheats! Just pseudocode or concepts would help loads, cheers.

So the ship can move and rotate in 3d space, and the turrets are children of the ship sitting on it, with an initial 0,0,0 rotation relative to it and a defined xRotMin, xRotMax etc… ie I want to say the turret can rotate -45 to 45 degrees in x etc.

So for a list of possible targets, I want to check that each is within that angular range, and if so rotate towards the target smoothly - bearing in mind the ship it’s sitting in could be moving under it.


Matt the Pie