Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Proper way of moving rope end points
#1
Hi,
 I've added pins on both ends of the rope. I want to know whether I've used the right implementation to move the rope end points. I've created configurable joints on the rope end point node and dragging it using rigidbody MovePosition. I can't use force here as I want the end point knob to move along with my finger. Though I've applied max limit on the knob distance how far player can drag, it still break physics sometimes when I drag fast. Is there any possibility to avoid happening ?


Code:
Vector3 maxDist = otherEnd.transform.position + dir *  Mathf.Clamp(dist, 0, knobDistance);
maxDist.y = -8f;// yPos;
rb.MovePosition(maxDist);


Code:
Transform AttachJoint(Rigidbody rb, Vector3 attachmentPosition)
{
    GameObject go = new GameObject("Attachment Point");
    go.hideFlags = HideFlags.HideInHierarchy;
    go.transform.position = attachmentPosition;

    var newRb = go.AddComponent<Rigidbody>();
    newRb.isKinematic = true;

    var joint = go.AddComponent<ConfigurableJoint>();
    joint.connectedBody = rb;
    joint.configuredInWorldSpace = true;
    joint.xDrive = NewJointDrive(force, damping);
    joint.yDrive = NewJointDrive(force, damping);
    joint.zDrive = NewJointDrive(force, damping);
    joint.slerpDrive = NewJointDrive(force, damping);
    joint.rotationDriveMode = RotationDriveMode.Slerp;

    return go.transform;
}

private JointDrive NewJointDrive(float force, float damping)
{
    JointDrive drive = new JointDrive();
    drive.mode = JointDriveMode.Position;
    drive.positionSpring = force;
    drive.positionDamper = damping;
    drive.maximumForce = Mathf.Infinity;
    return drive;
}

Also, sometimes I see weird behavior after completing cursor.ChangeLength. You can see one or two rope particles at random location still alive in the scene.


Attached Files Thumbnail(s)
                   
Reply


Messages In This Thread
Proper way of moving rope end points - by kripa1415 - 05-06-2024, 02:23 PM