Search Unity

How to make a Configurable Joint ignore connected body Rotation?

Discussion in 'Physics' started by Rafael-Barbosa, May 23, 2018.

  1. Rafael-Barbosa

    Rafael-Barbosa

    Joined:
    Apr 14, 2013
    Posts:
    288
    Hey guys,
    so.. I'm working on a VR game and I'm currently figuring out Two handed weapons, I'm using a configurable joint in order to make it work, in short, it is working just as I want it to as long as I don't rotate the controller in any way. What's happening is that the connected body (which is the primary hand) is rotating, and this is making the joint object rotate too, which in turn messes up my joint's TargetRotation. Does anyone know how to ignore the connected body's rotation? I've searched all around but joints don't seem like a very documented thing D:

    Here is my code and some visualization of the issue:





    Code (CSharp):
    1.     public Transform target;
    2.  
    3.     void Update () {
    4.  
    5.  
    6.         Vector3 relativePos = target.position - transform.position;
    7.         Quaternion rotation = Quaternion.LookRotation(relativePos);
    8.         rotation = Quaternion.Inverse(rotation);
    9.         GetComponent<ConfigurableJoint>().targetRotation = rotation;
    10.     }
     
  2. Rafael-Barbosa

    Rafael-Barbosa

    Joined:
    Apr 14, 2013
    Posts:
    288
    I was able to fix this issue! Since there is very little VR documentation out there, I'm gonna write the answer down.

    Use 2 different configurable joints on the same object. On for the object itself, which will get the first hand's position and one for the second hand.
     
    radarhead7 likes this.
  3. radarhead7

    radarhead7

    Joined:
    May 4, 2020
    Posts:
    2
    Hey, I hate to wake up a long-dead thread- but, is there any chance you could give additional detail on how you solved this problem?

    I think I'm having the same problem (Character arm has the joint, torso/controller is the connected body, arm 'looks' at the mouse position in world, but target rotation doesn't account for the rotation of the torso parent, so the arm points at a 90 degree angle from the correct position). Might not be the same thing, since I'm not working in VR, but your thread seems to be the closest match so far.

    I tried this "2 configurable joints" idea, but I can't figure out how to call them separately, so the issue persists because both joints conflict.
     
  4. Rafael-Barbosa

    Rafael-Barbosa

    Joined:
    Apr 14, 2013
    Posts:
    288
    Hey,

    I'm very sorry but I dont really remember much from this project :(
    I tried re-reading what I wrote but I didn't really remember much