Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Get aggregate transformation resulting from multiple RotateAround operations

Discussion in 'Scripting' started by fahruz, Jul 7, 2021.

  1. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    Transform.RotateAround changes both position and rotation. If the operation is applied iteratively at each update of an object in a script, how can I get the combined aggregate transformation to then apply it to another object (and how)?
     
  2. TheFunnySide

    TheFunnySide

    Joined:
    Nov 17, 2018
    Posts:
    192
    You are performing a Matrix multiplication like this. Where R is the rotation arround a point matrix.

    T_newPos = T_oldPos x R; // Rotation repeated every frame

    If you save your matrix somewhere then you can apply it to anything . Note that this matrix contains the angle of rotation which is based on the time since last frame.
     
  3. fahruz

    fahruz

    Joined:
    Mar 5, 2020
    Posts:
    57
    Yes, since there doesn't seem to be direct functional support in Unity for that, I was also assuming that I'd have to resort to using the transformation matrix (like probably Matrix4x4.TRS).
    If you or somebody could provide Unity code to do what I described above, that would be awesome.