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
#2
(05-06-2024, 02:23 PM)kripa1415 Wrote: I've added pins on both ends of the rope. I've created configurable joints on the rope end point node and dragging it using rigidbody MovePosition.

Hi!

If you've pinned the rope ends to rigidbodies, what do you need the configurable joints for? Joints are meant to constraint two rigidbodies together, but as far as I understand your use case of there's no need to do this?

Maybe you're using the configurable joint to keep the end knob in place on the board when the user is not dragging it around? If that's the case it would be far easier to just set the rigidbody to kinematic.


(05-06-2024, 02:23 PM)kripa1415 Wrote: I can't use force here as I want the end point knob to move along with my finger.

Why not? A force is just a mass-weighted acceleration, that is, a change in velocity. If you set the velocity such that it takes the end point knob to the position of your finger (plus some damping to avoid overshoot) it will follow the finger perfectly.

(05-06-2024, 02:23 PM)kripa1415 Wrote: 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 ?

The whole point of using physics for this is that you don't need to artificially set a distance limit: once the rope is completely taut, it will apply a force to the end knob that is equal in magnitude (but opposite in direction) to the force that the knob is applying on the rope (since the user is dragging the knob around). At that point, both forces cancel out and it won't be possible to continue pulling the rope.

kind regards,
Reply
#3
So you mean If I use rigidbody AddForce with some damping factor to move the knob around will it solve physics breaking issue?
I am attaching knob to a configurable joint and pulling configurable joint with its own rigibody MovePosition.
So you are saying that joints are not required here just use knob rigidbody to move around ?
Reply
#4
(07-06-2024, 07:57 AM)kripa1415 Wrote: So you mean If I use rigidbody AddForce with some damping factor to move the knob around will it solve physics breaking issue?


Correct.

(07-06-2024, 07:57 AM)kripa1415 Wrote: I am attaching knob to a configurable joint and pulling configurable joint with its own rigibody MovePosition.

MovePosition is a method of Rigidbody. The joint is doing nothing at all.

(07-06-2024, 07:57 AM)kripa1415 Wrote: So you are saying that joints are not required here just use knob rigidbody to move around ?

That's right: joints exist to be able to constrain multiple rigidbodies together. If you only have one rigidbody at each end, there's no use for them.
Reply