Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding pin constraints to a rope gives it velocity
#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


Messages In This Thread
RE: Adding pin constraints to a rope gives it velocity - by EmmetOT - 18-04-2020, 08:23 PM