child lookat another child

so I have a child object that I want to move/rotate with the parent like it normally would but also I want it to rotate on one axis to point at the child of a sibling object. I have this code which works until the parent object rotates, in which the object maintains it global rotation and doesn’t rotate with the parent. Obviously this doesn’t take into account local rotation, but I have tried implementing it in various ways I have seen on the internet but nothing gets close to working. If anyone can point me in the right direction It would be really appreciated.

 public Transform target;

void Update(){
 Vector3 targetPostition = new Vector3( this.transform.position.x, target.transform.position.y, target.transform.position.z ) ;
    		this.transform.LookAt( targetPostition) ;
}

public Transform target;

	// Update is called once per frame
	void Update () {
        this.transform.LookAt(target, Vector3.up);
	}

You don’t need to calculate the position, you can just use the Transform.
Worked for me :slight_smile: