Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Linking multiple rigidbodys with hinge joint

Discussion in 'Physics' started by NovaDynamics, Sep 28, 2017.

  1. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    Hey guys!

    I'm trying to make a tank-style tread system using rigidbody sections joined together with hinge joint. The end goal is for it to function like this:

    I can create an array of rigidbodys, and connect them all to each other, but if I put them under much of a load at all they start glitching in all different directions. I have tried everything I can think of to fix this, with no result:

    Tried using character joints.
    Tried using configurable joint with a small linear limit (and spring)
    Tried writing a script that would modify the transforms of the track components to keep them together if they started coming apart:
    Code (CSharp):
    1.  
    2.         Vector3 localtrack1 = track1.transform.InverseTransformDirection(track1.position);
    3.         Vector3 localtrack2 = track2.transform.InverseTransformDirection(track2.position);
    4.         Vector2 t1v = new Vector2(localtrack1.z, localtrack1.y);
    5.         Vector2 t2v = new Vector2(localtrack2.z, localtrack2.y);
    6.         Vector2 dif = track2.position - track1.position;
    7.      
    8.         Vector2 dif = track2.position - track1.position;
    9.         if (dif.magnitude > .16)
    10.         {
    11.             float multiplier = 0.16f / dif.magnitude;
    12.            Vector3 scale = new Vector3(multiplier, multiplier,multiplier);
    13.             Vector3 newdif = dif * multiplier; // Vector3.Scale(dif,scale);
    14.  
    15.             Vector3 newpos = track1.position + newdif;
    16.  
    17.  
    18.             Debug.Log(track2.position + " --> " + newpos);
    19.             track2.position = newpos;
    20.          
    21.          
    22.            
    23.        }
    None of these have worked at all. Is there a trick I'm missing? Thanks!
     
  2. NovaDynamics

    NovaDynamics

    Joined:
    Sep 6, 2017
    Posts:
    25
    I figured it out!! All I have to do is set
    Code (CSharp):
    1. Time.fixedDeltaTime = 0.0005f;
    And it works beautifully!