RotateAround object in local space

Hi, thanks for any help.

I’ve been looking around trying to find the answer to this, but what I’m finding keeps either being out of date or doesn’t seem to work.

Essentially I want a game object, A, to be in constant orbit around another game object, B, at a consistent radius and continue to do so smoothly when B rotates 90 degrees. RotateAround works in world space which would be fine if B didn’t rotate, but I either need it to work in B’s local space or come up with a different solution.

Any thoughts? Thanks again.

My solution is pretty inelegant (I’m not great with Quaternions), but you could add a transform around the location of the rudder (just a simple point, you can use a 3D object to check its position relative to the object, then apply the following:

	void Update () {
        if (Input.GetKey(KeyCode.W)
            transform.Rotate(Vector3.right, -0.5f); // Pitch down
        else if (Input.GetKey(KeyCode.S)
            transform.Rotate(Vector3.right, 0.5f); // Pitch up
        else if (Input.GetKey(KeyCode.A))
            transform.Rotate(m_rudder.up, -0.5f); // Yaw left
        else if (Input.GetKey(KeyCode.D))
            transform.Rotate(m_rudder.up, 0.5f); // Yaw right

m_rudder references the transform I stuck over the rudder. I don’t have a submarine model, so I just made a capsule and stuck the transform at the back. Seems to work ok for me.