I would like someone to describe me how to use a PID controller to rotate a rigidbody with AddTorque to a specific position. (like a spacecraft that rotates the Y axis of rotation towards Camera.forward for example). Can anyone show it to me with a script?
Actually I already use this script to rotate with AddTorque but the object almost never stops at the precise point.
Vector3 camForward = Camera.main.transform.forward;
Vector3 rbForward = rb.transform.forward;
Vector3 torqueY = Vector3.Project(torque, Vector3.up);
Vector3 torque = Vector3.Cross(camForward, rbForward);
rb.AddTorque(torque);
rb.AddTorque(-rb.angularVelocity);