Get object A pos x and pos Y relative to the center.
Use in Atan2.
Use result of atan as rotation for object B.
Eventually adjust that rotation with whatever degree (±0 to 180) to make it appear at the desired angle.
You’re telling Unity, “Okay, take your own world-space position (transform.position), and tell me what that position is in your own local space (transform.InverseTransformPoint)”. Note that these two are the same - “relative” is always going to come out to 0,0,0. (Or within a rounding error of that, anyway)
One of those “transform.” in your code should be “objectB.transform.”, I think.
But, it’s not behaving the way I expected, when I move Object A along the X axes with Y=0, Object B rotation around Z axes just snaps between +180° and -180°.
I want a smooth transition between these two values when I move Object A along the X axes with Y=0.
You might be hitting a “corner case” with y=0. Do the other values of y behave correctly? If so, you need to test for the y=0 case and create a workaround. This can happen with trig functions…or really, any function with a division, because you might divide by 0 inadvertently.