Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by themusicdork · May 26, 2011 at 09:41 AM · physicsrigidbodyjointpivotropehinge

Hinge Joint? Unconstrained.

Basically I want to have a connection between two (preferably not rigidbodies but if it needs a joint I can make a workaround) GameObjects. think of a rope, but it doesn't have to be rendered or have segments. When the two objects are connected if one object moves past the rope length it will either pull the connected object with it (if the other object isn't static) or pull the object back to the connected object.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · May 26, 2011 at 10:02 AM

All joints only works with rigidbodies since they have to add forces to both attached objects. You can set one of them to be kinematic, but the other one have to be non kinematic. Otherwise it will bypass physics simulation.

A Hinge Joint isn't a slider. it normally have a constant length (which can stretch a bit due to spring property). It sounds like you want just to limit an object to move further away.

If you don't use rigidbodies and joints, you can handle the case yourself. Is the one point at a fix position? If so the object that moves away just needs to check the distance and move it back until the distance is ok.

 //C#
 public Transform fixPoint;
 public Transform movingPoint;
 public float maxDistance = 10.0f;
 void Update()
 {
     Vector3 dir = fixPoint.position - movingPoint.position;
     float dist = dir.magnitude - maxDistance;
     if (dist > 0)
     {
         movingPoint.Translate (dir.normalized * dist * Time.deltaTime,Space.World);
     }
 }

If both points can be moved it gets a bit tricky. If you want the same behaviour like the HingeJoint you just need to affect both points (the second point just in the opposite direction). That would enable one point to pull the second point towards he's moving.

If it should not pull the other object the above script should only be executed for the point that is moving. If both can move you have to switch the two points.

Comment
Add comment · Show 2 · 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 themusicdork · May 26, 2011 at 10:22 AM 0
Share

Well I can simply parent the object to a temporary rigidbody if using joints is easier.

But yeah, I want a hinge joint that ins$$anonymous$$d of keeping the object at a certain distance, keep it in a certain distance. So if the object is moving toward the object it is connected to, it will move freely until it get to the max distance. (at which point they will spring together)

I thought a spring joint would be easier but they are retarded. (when you create one it uses the starting positions ins$$anonymous$$d of the current ones). P.s. I was hoping for it not to "snap" back but for it to be pulled back.

avatar image Bunny83 · May 26, 2011 at 11:48 AM 0
Share

If you want it that way you can use the script above. It behaves like a spring. The "force" grows proportional to the distance, but only if it's greater than the maxDistance. You can move the object within the sphere with a radius of maxDistance freely. Only if it gets outside this script will "pull" it back. If you don't want the smooth return over time you can use LateUpdate and remove the Time.deltaTime. That way it's a hard stop at the sphere border.

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Hinge Joints, distance to connected body 1 Answer

How to create a freely swinging "rope" of modifiable size between two rigid bodies? 0 Answers

Hinge Joints that Don't Limit? 0 Answers

Why are my hinge joints inaccurate? 1 Answer

Truck-Trailer Hinge 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