Object dragging

Hello!
I’m trying to implement dragging of objects with different masses (like in Half-Life 2, Viscera Cleanup Detail, etc.). So far I have a dragger with Rigidbody and ConfigurableJoint on a player’s child. It kinda works but it has some flaws.

So how it should be:

  • It shouldn’t rotate midair, but should rotate when it touches surfaces or else if needed.
  • If object clings on something, it should act like it’s on spring. I read docs and I tried to play with parameters but had no success. It just psychotically jitters (see video). Before ConfigurableJoint I was using SpringJoint and it was like I want, but problem with SpringJoint was that object was rotating and flying around like crazy.
  • If player drops object while moving or rotating, object should save inertia. With SpringJoint it was like that, now it just falls down (see video).

I’ve also added Linear Limit, because without it objects were jittering midair but now objects are weirdly swaying (see video).

I apply these parameters to ConfigurableJoint:

cj.autoConfigureConnectedAnchor = false;
cj.anchor = cj.axis = cj.secondaryAxis = Vector3.zero;
cj.connectedAnchor = hit.rigidbody.centerOfMass;
cj.xMotion = cj.yMotion = cj.zMotion = cj.angularXMotion = cj.angularYMotion = cj.angularZMotion = ConfigurableJointMotion.Limited;
SoftJointLimit linearLimit = cj.linearLimit;
linearLimit.limit = draggerLinearLimit;
cj.linearLimit = linearLimit;
cj.breakForce = draggerBreakForce;
cj.connectedBody = hit.rigidbody;

This may solve your problem: MS Move Objects | Physics | Unity Asset Store

In the asset, I use AddForce, MovePosition, or velocity to move the Rigidbody. AddForce does what you are looking for.

Hey there,

Just try again with the spring joint. When you attach it, set useGravity of the target to false and increase angularDrag on the target, too (remember to set it back to what it was when you release the object). The spring joint can also apply damping, which you should also adjust to your needs.

Note that the value for “spring” and “damping” of the spring joint need to scale with the mass of the target object.

You’re on a good way, keep trying!

Yep. Spring joint works fine. I did dragging similar to hl2 myself a few years ago. Also don’t forget to deattach dragged object when it’s too far from players child :wink:

I tried many different values for Spring and Damper, but object is either still flying like crazy or too slow. If I change object’s drag, it becomes even weirder.