I'm making a tank game in unity and I want to rotate tank's turret with mouse. The main Camera is a child of the turret.
I've tried this:
Ray dir = MainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(dir, out hit)){}
Turret.transform.LookAt(hit.point);
But the turret starts to rotate infinitely. I think it's because of MainCamera is a child of Turret. So I don't know how to do this.
Can you help me?