• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by LightningDalek · May 26, 2020 at 03:27 PM · physicsbugconfigurable joint

Configurable joint set to limited locking when connected.

Hey everyone, I have a problem that I'm pulling my hair out over and I've spent 10 hours or so trying to fix it, the problem is simple. I am creating a VR game I have a mag for a gun and I am trying to create a script that allows me to slot it in using a configurable joint. I create the joint at runtime when I connect the gun and mag, I have the joint set to limited on the x-axis but for some reason, it locks and won't slide, I've done a bunch of logging, checked my colliders (even though that shouldn't matter because joint collision is off.), and the script is doing exactly what its meant to do. The problem is fixed when I let go of the mag, I'm holding it using a separate configurable joint and no code is being called that interacts with the mag in any way except that the configurable joint connecting it to my hand is destroyed. After letting go the joint works as expected and can slide in and out of the gun perfectly. I can even grab the mag again after letting go and it will still work.

So to recap, my problem is that an unlocked joint locks when I create it and connect it to somet$$anonymous$$ng, disconnecting a previously connected joint fixed the problem but does not appear to be the source of the problem as the mag can be connected without being held, the joint then functions normally.
Here is my code for creating the joint:


    SetupJoint();
    locked = false;

 private void SetupJoint()
         {
             Debug.Log("creating joint");
             joint = gameObject.AddComponent<ConfigurableJoint>();
 joint.anchor = new Vector3();
             transform.rotation = currentSlot.transform.rotation * Quaternion.Inverse(slotPoint.localRotation);
             transform.position = currentSlot.transform.position - (slotPoint.position - transform.position);
             GetComponent<Rigidbody>().rotation = currentSlot.transform.rotation * Quaternion.Inverse(slotPoint.localRotation);
             joint.connectedBody = currentSlot.parentRigidbody;
             joint.autoConfigureConnectedAnchor = false;
             joint.connectedAnchor = currentSlot.transform.localPosition - Quaternion.Inverse (currentSlot.parentRigidbody.transform.rotation) * (slotPoint.position - transform.position);
             joint.connectedAnchor += currentSlot.transform.localRotation * Vector3.up * currentSlot.depth;
 
             joint.xMotion = ConfigurableJointMotion.Locked;
             joint.zMotion = ConfigurableJointMotion.Locked;
             joint.yMotion = ConfigurableJointMotion.Locked;
             joint.angularXMotion = ConfigurableJointMotion.Locked;
             joint.angularYMotion = ConfigurableJointMotion.Locked;
             joint.angularZMotion = ConfigurableJointMotion.Locked;
 
             joint.axis = currentSlot.transform.localRotation * Vector3.forward;
 
             SoftJointLimit limit = joint.linearLimit;
             limit.limit = currentSlot.depth / 2;
             limit.contactDistance = 0;
             joint.linearLimit = limit;
 
             joint.projectionAngle = 3;
             joint.enablePreprocessing = false;
             joint.projectionMode = JointProjectionMode.PositionAndRotation;
 }

    

    public bool locked
            {
                get
                {
                    return joint.xMotion == ConfigurableJointMotion.Locked;
                }
                set
                {
                    if (value == (joint.xMotion == ConfigurableJointMotion.Locked))
                        return;
                    if (value)
                        joint.anchor += currentSlot.transform.localRotation * Vector3.up * currentSlot.depth / 2;
                    else
                        joint.anchor -= currentSlot.transform.localRotation * Vector3.up * currentSlot.depth / 2;
                    joint.xMotion = value ? ConfigurableJointMotion.Locked : ConfigurableJointMotion.Limited;
                    //Debug.Log("locked");
                }
            }
    

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

220 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

If a joint has a Connected Body, does it ignore the Anchor position? 1 Answer

Double gravity when standing on two colliders, bug? 1 Answer

Clothes goes mad with a near-zero time scale? 0 Answers

IgnoreCollision affecting children & unrelated objects when it should'nt ? 0 Answers

How can i fix weird physics bug/glitch ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges