Search Unity

Rotation of a point about another point

Discussion in 'Physics' started by PhoenixAdvanced, May 30, 2021.

  1. PhoenixAdvanced

    PhoenixAdvanced

    Joined:
    Sep 30, 2016
    Posts:
    316
    Hi,

    I have run into an issue a few times in my project where I have to rotate an object or a point around a specific center. I am currently solving the issue like this:

    Code (CSharp):
    1.          
    2. GameObject ro = new GameObject();
    3. ro.transform.position = rotationobject.transform.position;
    4. ro.transform.rotation = Quaternion.identity;
    5.  
    6. GameObject go = new GameObject();
    7. go.transform.position = pos;
    8.  
    9. go.transform.parent = ro.transform;
    10.  
    11. ro.transform.rotation = rotationobject.transform.rotation;
    12.  
    13. go.transform.parent = null;
    14.              
    15.  
    Which is obviously messy, but it does work.

    What is the correct way to solve this? I'm guessing there is purely mathematical way, involving quaternions/matrices, possibly, and not creating gameobjects?

    Or could I use transform.rotatearound?