• 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 Aldwoni_legacy · Jun 06, 2011 at 10:45 AM · javascriptjointfixedjoint

Change length of fixed joint

I have 2 cubes connected to an Fixed Joint. Now I want to move one cube away from the other cube. (make the distance between the cubes bigger).

Is there a better solution than kill the fixed joint, change the distance and then create a new fixed joint?

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

5 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Statement · Jun 06, 2011 at 12:22 PM

Maybe you could try changing from using a fixed joint to a configurable joint instead?

Configurable Joints are extremely customizable. They expose all joint-related properties of PhysX, so they are capable of creating behaviors similar to all other joint types.

Comment
sneftel
Aldwoni_legacy

People who like this

2 Show 5 · Share
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
avatar image Aldwoni_legacy · Jun 06, 2011 at 01:00 PM 0
Share

is there a tutorial for using configurable joints?

avatar image Statement · Jun 06, 2011 at 01:06 PM 0
Share

Didn't the documentation provide enough information? I am unaware of any specific tutorial on them, but try google. "unity3d configurable joint tutorial". The documentation also suggest to experiment a bit to find the right feeling, and I think it's a good way to get to grip with it. I'd narrow down on the properties you're after, and try get those to work accordingly. When you found your set of variables you want to control, just write a script that change the settings as needed. I don't know if changing the setup of a joint require the delete/create method you described or not. Don't be afraid to play around a bit :)

avatar image Aldwoni_legacy · Jun 06, 2011 at 02:16 PM 0
Share

maybe I don't look far enough but the only thing I can find is that people say " if any feature of Unity was deserving a video demonstration of it's functionality, it's Configurable Joints." with replies like " Indeed. A example project, with an accompanying video tutorial, to demonstrate what you should start messing with, in order to learn quickly, would be good."

I'm currently trying to create a FixedJoint from a Configurable Joint.

avatar image Aldwoni_legacy · Jun 07, 2011 at 02:42 PM 0
Share

I've made something like a Fixed joint with a Configurable joint, but I can't change the distance between them.

avatar image Aldwoni_legacy · Jun 28, 2011 at 08:23 AM 0
Share

Finally found an solution for my problem, with help from: http://forum.unity3d.com/threads/41147-Moving-hinge-joint-in-a-script-has-no-effect

avatar image

Answer by Owen-Reynolds · Jun 07, 2011 at 11:27 PM

Turns out any attempt to move the hinged object using transform.position will be snapped back to where it started. you can't disable the hinge, but you can unscrew the far end:

 // Save end of hinge, then unscrew it:
 Rigidbody RB = transform.hingeJoint.connectedBody;
 transform.hingeJoint.connectedBody = null;
 
 // Tricky, since anchor is local. No easy way to move it "world backwards":
 //transform.hingeJoint.anchor += Vector3.forward  * 0.1f;

 // Can now move unconnected hinge:
 transform.position -= Vector3.forward*0.2f;
 
 transform.hingeJoint.connectedBody = RB; // screw it back in
Comment
Aldwoni_legacy
Max-Pixel

People who like this

2 Show 4 · Share
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
avatar image Aldwoni_legacy · Jun 21, 2011 at 08:36 AM 0
Share

What did I do wrong?

var aap : GameObject;

var beer : GameObject;

script = this.gameObject.GetComponent(speler);

aap = script.aap;

beer = script.beer;

function FixedUpdate(){ verticaal = Input.GetAxis(script.verticaal);

if(verticaal != 0)

     {

         var joint : FixedJoint;

         joint = aap.gameObject.GetComponent(FixedJoint);

         Destroy(joint);

         aap.rigidbody.velocity = Vector3(0,verticaal,0);

         aap.AddComponent(FixedJoint);

         joint.connectedBody = beer.rigidbody;

     }

}

avatar image Owen-Reynolds · Jun 22, 2011 at 02:37 AM 1
Share

Like you implied, this "destroy then remake" method may not be the best approach. Lots of values you hand-tweaked need to be recreated on the new one.

avatar image Aldwoni_legacy · Jun 22, 2011 at 10:17 AM 0
Share

but now the he can'f find his connectedBody back. Do you know a better approach?, I would like to know.

avatar image Aldwoni_legacy · Jun 23, 2011 at 02:58 PM 0
Share

I solution looking a bit like your is almost working. I only need to get the anchor of the joint to be at the location of the connectebody.(I don't expect any errors after that but are not sure)

avatar image

Answer by Ye · Feb 14, 2014 at 03:22 AM

Use configurable joint, linearLimit

ConfigurableJoint configurableJointComp = GetComponent(); SoftJointLimit softJointLimit = new SoftJointLimit(); softJointLimit.damper = 1f; configurableJointComp.linearLimit = softJointLimit;

Comment
BurningKrome

People who like this

1 Show 0 · Share
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
avatar image

Answer by BurningKrome · Feb 24, 2015 at 10:18 AM

In addition to the above, defining the X-drive, y-drive, and z-drive in conjunction with a target position/velocity can be used to move the object to specific distances, creating a "length" to the joint arm. Be sure to set the x/y/z-drive spring, as this is what pushes the object out to the limit.

Comment

People who like this

0 Show 0 · Share
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
avatar image

Answer by K0ST4S · Dec 24, 2018 at 09:26 PM

If it's 2D game, use Distance Joint 2D. You can write something like: joint.distance = yourDistance; or set EnableCollision and Max Distance Only for minimum distance.

Comment

People who like this

0 Show 0 · Share
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

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

6 People are following this question.

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

Related Questions

how to move object with joint 2 Answers

Multiple conected bodies for joint? 0 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Fixed joint - not really fixed? 5 Answers

How can I Change the "Allowance" in a joint? 0 Answers


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