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

Question Change from Coordinate System A to B

Discussion in 'Scripting' started by TheHeftyCoder, Jul 26, 2022.

  1. TheHeftyCoder

    TheHeftyCoder

    Joined:
    Oct 29, 2016
    Posts:
    82
    Hey guys, I'd really appreciate some help on this one.

    Given 2 coordinate systems A and B where
    1) xA is an initial Vector3 position, rA is an initial Quaternion rotation
    2) xB is an initial Vector3 position, rB is an initial Quaternion rotation

    How can I then transform a random (position, rotation) from A into B?
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    Can you not just... set them to B's values?
     
  3. TheHeftyCoder

    TheHeftyCoder

    Joined:
    Oct 29, 2016
    Posts:
    82
    Hello! What exactly do you mean? Let me describe what I want by only incorporating position.

    Screenshot_5.png

    So, from here, to go from coordinate system A to B, you simply have to:

    moveB = xB + (moveA - xA) (well, given these axis the equation might not be 100% correct, but you get what I'm saying)

    That though doesn't incorporate any rotational differences and I'm kind stuck on how to do this correctly using quaternions as well.
     
  4. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    Is this a math question, or a scripting one? If it's a scripting one, you can just do A.transform.position = B.transform.position.
     
  5. TheHeftyCoder

    TheHeftyCoder

    Joined:
    Oct 29, 2016
    Posts:
    82
    It isn't a scripting question. It's a 3d / game math question. Should I post it in general support?
     
  6. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,593
    No, although I would find it difficult to find anyone who really knows much about Quaternions.

    I still don't quite understand what you're trying to get though, your original question sounded like you wanted to find X, where X = xA - xB to find the Vector to translate from one to the other, but in the example you showed it was something completely different.

    For Quaternions, it would be as simple as R * rA = rB to get the Quaternion to rotate into it, it would just be rA multiplied by the inverse of rB, or flipping the X, Y, and Z values. If you had a Quaternion of (1, 2, 3, 4), the inverse would be (1, -2, -3, -4). This is just from Googling how to do that though, it could be wrong.