How to get the required rotation in eulers from a source in order to align/rotate towards a target

I have a turret as shown below:

I have a target transform.
I want the turret ARM to move on the up axis, and the WEAPON to move on the horizontal axis in order to align to a target.

I just want to know how I can get the angle required for each component to align to the target.

Thanks

I would just use Quaternion.LookRotation, dependant that ‘forward’ and ‘up’ are set up correctly on your turret arm. Then Quaternion.RotateTowards it.

Something like:

Vector3 targetDirection = targetTransform.postion - turrentArmTransform.position;
targetDirection.y = 0f;
Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
Quaternion rotation = Quaternion.RotateTowards(turrentArmTransform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
turrentArmTransform.rotation = rotation;

Get a direction to your target, flatten it, make a rotation aimed at it, and then rotate your turret arm towards it.

This is of course, one of many possible solutions.

How do I set forward and up correctly, like what are the directions for X, Y, Z? thanks

Forward: The direction from your target to your object (target.position - this.transform.position)
Up: World-Space Up-direction (normally Vector3.up)

If you set your translate handle to local, the blue arrow should point in the direction that should logically be ‘forward’. Ergo, point towards where the turret should be aiming.

As a bit of modelling advice on the side too, in this instance, your origin point should be at the base of your arm. Ergo, the point where you logically want the model to rotate around, and be positioned against something else.

Both of these are done in your modelling program, dependant on being exported correctly too.