Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding pin constraints to a rope gives it velocity
#1
I'm working on a 2d grappling hook situation. I'm having the same rope stretchiness issues as other users are having where even with all the settings the same as the demo, it still seems very stretchy. (I've messed with distance constraints, unity's physics timestep size, substeps, source object's mass, etc.) However that issue wouldn't bother me that much if it weren't for this:

Creating the rope works fine, but when I add pin constraints on the rope (one on the source object, one on the hit object) it seems to also impart some velocity to the rope. The source object flies quickly towards the hit object, often at some speed.

If I only pin the rope to the hit object, the rope wiggles around and flies upwards before hanging.

If I only pin the rope to the source, it still imparts some velocity on the source object in the direction of the hit object, which obviously makes no sense since I've effectively just added a loose rope to the object and nothing more.

Basically it seems the rope by default starts with velocity on each particle. I'd like to know if there's a way to remove this velocity. I couldn't see an obvious method to do so.

Thanks!
Reply
#2
Hi,

Rope particles are always instantiated with zero velocity. Make sure the offset you're passing to the pin constraint is the particle position expressed in the object's local space. Any other offset value will pin the particle to a position other than its current one, imparting a velocity to it immediately (to reach the offset position).
Reply
#3
(18-04-2020, 07:52 PM)josemendez Wrote: Hi,

Rope particles are always instantiated with zero velocity. Make sure the offset you're passing to the pin constraint is the particle position expressed in the object's local space. Any other offset value will pin the particle to a position other than its current one, imparting a velocity to it immediately (to reach the offset position).

Thanks for the reply! Here's the code I use to create the pin constraints:

Code:
private void Pin(Vector3 attachPoint, ObiColliderBase hitCollider)
{
   m_attachedPoint = attachPoint;
   m_attachedCollider = hitCollider;

   // Pin both ends of the rope (this enables two-way interaction between character and rope):
   ObiConstraints<ObiPinConstraintsBatch> pinConstraints = m_ropeBlueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
   ObiPinConstraintsBatch batch = pinConstraints.GetFirstBatch();

   batch.AddConstraint(0, m_ropeSourceObiCollider, Vector3.zero, Quaternion.identity);
   batch.AddConstraint(m_ropeBlueprint.activeParticleCount - 1, m_attachedCollider, m_attachedCollider.transform.InverseTransformPoint(m_attachedPoint), Quaternion.identity);

   batch.activeConstraintCount = 2;
}

I've worked out how to affect particle velocity now, and while it does seem to reduce the effect, the rope still oscillates a lot instead of hanging slack. Here's the code I added to reduce velocity. I made it a coroutine so I could experiment with doing it over multiple frames.


Code:
private IEnumerator Cr_ReduceVelocity(int frames = 1)
{
   for (int i = 0; i < frames; i++)
   {
       yield return null;
               
       foreach (int index in m_rope.solverIndices)
       {
           m_solver.velocities[index] = Vector3.zero;
           m_solver.angularVelocities[index] = Vector3.zero;
       }
   }
}

Here's a gif of the result if I run this for 30 frames after the pins have been generated. Note the way the ball is pulled upwards sharply, and the crazy oscillations afterwards. Removing the velocity has improved the pulling up, but not entirely removed it.

[Image: ELbLGvY.gif]

Some other information: (I made a ScriptableObject so I could modify them all in one place)

[Image: GAVoA1R.png]

Thank you again!
Reply
#4
Make sure you’re not pinning a particle inside a collider that’s set to collide against it, as both constraints (collision and pin) cannot possibly be met simultaneously, causing constant jittter. This is warned against in the pin constraints documentation.

The solution would be to deactivate collisions between the particles that must lie inside of the collider and the collider itself, setting their phases to the same value.
Reply
#5
(18-04-2020, 11:23 PM)josemendez Wrote: Make sure you’re not pinning a particle inside a collider that’s set to collide against it, as both constraints (collision and pin) cannot possibly be met simultaneously, causing constant jittter. This is warned against in the pin constraints documentation.

The solution would be to deactivate collisions between the particles that must lie inside of the collider and the collider itself, setting their phases to the same value.

Thanks, this has stabilized things greatly!
Reply