Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Jun 23, 2014 at 12:45 AM by ikelaiah for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by ikelaiah · Jan 08, 2014 at 11:44 PM · physicsjointsconstraintsphysx

Is there a Distance Constraint 3D or Distance Joint 3D in Unity?

Is it possible to do a distance constraint/joint constraint in Unity? For example, consider 2 cubes, 2 unit apart, as the following;

 [ ]--2 units--[ ] (controllable)

If we move the box on the right up or down (by using keyboard control), it will retain same distance, 2 units exactly, as the following;

     [ ] (controllable)
     /
    2 units
   /
 [ ] 

It seems that we have Distance Constraint 2D, but is there a Distance Constraint 3D in Unity?

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by Dinosaurs · Jan 08, 2014 at 11:59 PM

I believe the best way to do this would be using a ConfigurableJoint and setting it's linear limit to the distance you want.

Comment
Add comment · 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
0

Answer by darkcookie · Jan 09, 2014 at 12:19 AM

well i would get the distance of 1 and compare it to the other ... from there you can set a constraint of distance to your likeing.

 var target : Transform; 
 private var myTransform : Transform;
 
 function Awake(){
 myTransform = transform; //here i cached the transform for performance
 }  
 
 function Distance(){
 var direction : Vector3 = target.position - myTransform.position;//declare direction
 
   if (direction.x > 2){
     //Your code here if the distance on the x is GREATER than 2
  }
   else if (direction.x < 2){
   //Your code here if the distance on the x is LESS than 2
  }
 }
Comment
Add comment · Show 3 · 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 darkcookie · Jan 09, 2014 at 12:20 AM 0
Share

or you can do a ray cast and measure the distance apart

avatar image ikelaiah · Jan 09, 2014 at 12:58 AM 0
Share

I'm not quite following your code. function Distance(){...} should be inside function Update() {...} isn't? Why do you use direction.x only? Thanks.

avatar image darkcookie · Jan 09, 2014 at 02:00 AM 0
Share

the distance is in a function and not in the update because you can call it whenever you want (if you want you can put it in the update function) its just for better control and performance , also i use x as an example ....you pick your vector and you can use this as a condition for the ConfigurableJoint like Dinosaur said.

Follow this Question

Answers Answers and Comments

20 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

Related Questions

Configurable Joint AccelerationDrive Flag 0 Answers

unity 3d configurable joint constraints gizmo makes no sense 2 Answers

How to add friction to Unity HingeJoint? 1 Answer

Can an ArticulationBody be joined to a Rigidbody? 1 Answer

How do I make a custom sliding 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