Constrain LookAt to Local Axis

I’ve been using the following code to constrain LookAt to a specific axis:

Vector3 lookAtPos = target;
lookAtPos.y = obj.transform.position.y;  // constrain y axis
obj.LookAt(lookAtPos);

This constrains to the global y axis. What I need to do is constrain to the local y axis that can be viewed with the local rotate handle. How is this possible?

Vector3 lookAtPos = target;
//first get a position relative to object
Vector3 lookAtPosLocalised = obj.InverseTransformPoint(target);
//offset it
lookAtPosLocalised.y = 0f; //replace zero with any offset needed
//convert localised position back
lookAtPos = obj.TransformPoint(lookAtPosLocalised);
obj.LookAt(lookAtPos);

Wow, thanks. I’ve been searching for that answer for hours. …I need to study math more :frowning: