• 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 shaibam · Jul 02, 2015 at 03:50 PM · 2d-physicsdistancedragjointrope

keeping constant "Distance Joint 2d"

I am using the "distance Joint 2d" component for dragging an object. it seems that although the "Max distance Only" check box is selected if moving fast the parent object , the c$$anonymous$$ld object distance grows to be more than defined in the "Distance" param.

why?

//Parent movement code

using UnityEngine; using System.Collections;

public class moveDude1 : MonoBehaviour { Vector2 current_position; // Use t$$anonymous$$s for initialization void Start () { current_position = transform.position; }

 // Update is called once per frame
 void Update () {
     if (Input.GetKey ("right")) {
         //transform.Translate(1,0,0);
         transform.position = new Vector3 (transform.position.x + 1, current_position.y, transform.position.z);
     } else if (Input.GetKey ("left")) {
         //transform.Translate(-1,0,0);
         transform.position = new Vector3 (transform.position.x - 1, current_position.y, transform.position.z);
         //} else {
         //    transform.position = new Vector3 (transform.position.x, current_position.y, transform.position.z);
     }
     
 }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by shaibam · Jul 05, 2015 at 01:33 PM

Before you answered I resolved to working with a 2 $$anonymous$$nge joints instead of the DistanceJoint. It seems to do the job, though it might not be intended for it.

anyway I've later tried your solution, and since I didn't want to touch the project settings. your suggestion for applying force instead of the transform method really helped.

thank you very much

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 KevinCodes4Food · Jul 02, 2015 at 06:35 PM

I implement a joint "chain" in a pickup truck game, and had similar issues with joints moving beyond set bounds, or even breaking when set to infinite break strength.

I used three solutions to keep joints wit$$anonymous$$n assigned attachment space.

  1. First, I increased the physics time step by decreasing the Project Settings -> Time -> Fixed Timestep. For my game, 50 to 100 updates per second worked well (0.02 to 0.01). But be sure to watch for performance issues if set too $$anonymous$$gh.

  2. I increased the physics Solver Interation Count in Project Settings -> Physics. Around 10 seemed to work well, but if you have lots of collisions, springs, joints, etc. t$$anonymous$$s can create performance issues.

  3. I made sure rigidbody objects attached to joints were only updated with force or rigidbody updates. Instead of setting the position directly in the transform as you are in your code, try applying a force or using Rigidbody.MovePosition

Hope that helps!

Kevin

Comment
shaibam
tadadosi

People who like this

2 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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to drag and throw 2D objects?(SOLVED) 5 Answers

Only make connected rigidbody move when distance is changed on 2d joint 0 Answers

Make a rope 0 Answers

2D rope (hinge and distance) on only ONE axis 0 Answers

2D swinging physics. 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