Search Unity

JointData creation question

Discussion in 'Physics for ECS' started by Vladimir-Borodin, Feb 2, 2020.

  1. Vladimir-Borodin

    Vladimir-Borodin

    Joined:
    Jun 1, 2017
    Posts:
    15
    What does it means "AinA" and "BinB" in this example?
    Code (CSharp):
    1. var jointData = JointData.CreateFixed(float3 positionAinA,
    2.                                                              float3 positionBinB,
    3.                                                              quaternion orientationAinA,
    4.                                                              quaternion orientationBinB);
     
  2. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    positionAinA is the position of body A's joint in body A's local space, and so on for the remaining arguments. For a simpler example, consider a ball and socket, which just takes a position in A and a position in B. The joint's job is to apply forces to the bodies at those points so that those positions are the same in world space. For the fixed joint, the same idea extends to orientation. If you imagine X,Y,Z axes coming out of the point in each body, the joint's job is to make A's axes line up with B's axes. So orientationAinA and orientationBandB determine which way the axes point in each body's local space.
     
    Vladimir-Borodin and steveeHavok like this.
  3. Vladimir-Borodin

    Vladimir-Borodin

    Joined:
    Jun 1, 2017
    Posts:
    15
    So, this is code to create joint between two existing entities:

    Code (CSharp):
    1. var BFromWorld = math.inverse(new RigidTransform(rotationB, positionB));
    2.  
    3. var positionAinA = float3.zero;
    4. var positionBinB = math.transform(BFromWorld, positionA); //positionA from world space to local B space
    5. var orientationAinA = math.mul(math.inverse(rotationA), rotationB); //relative rotation from A to B
    6. var orientationBinB = quaternion.identity;
     
    MaxAbernethy likes this.
  4. MaxAbernethy

    MaxAbernethy

    Joined:
    Mar 16, 2019
    Posts:
    53
    That looks right to me. If you pass those to JointData.CreateFixed(), you should get a joint that maintains the bodies' current relative transform.
     
    Vladimir-Borodin likes this.