Imagine an old sailing ship with cannons: they're pointed out at 90° angles from the ship's hull, so in order to fire them, you have to turn the whole ship so that the cannons are pointed at the target. I'm hoping to figure how to calculate "where to point the ship so that the cannons are aimed correctly," but for any possible cannon-angle (not just 90°) in 3D space.
I'm an experienced dev but a total 3D newb, so this vector stuff is wrinkling my brain. This is what I have right now, calculated from the child's (cannon's) gameObject:
Vector3 directionToAim = (transform.localRotation * (transform.position - target.position)).normalized;
It's working for side-facing weapons (like the sailing ship), but for forward-facing weapons it turns the parent in the opposite direction, directly away from the target. If I invert it to (target.position - transform.position) the forward-facing weapons work fine, but the side-facing weapons face the opposite way.
Also, my vague understanding is that it's better to use Quaternions for this, rather than Vector3, is that right? Can someone help me grasp how these parent/child rotations can be calculated?