I tried your suggestion. setting stretching scale to 1 and stretchCompliance 0 causing unity to crash. Attached rope creation code snippet. Sometimes its working but extremely slow
frame by frame and rope also not in good shape. Attached video link here.
https://drive.google.com/file/d/1jC1ghSt...sp=sharing
frame by frame and rope also not in good shape. Attached video link here.
https://drive.google.com/file/d/1jC1ghSt...sp=sharing
Code:
private IEnumerator CreateRope(ObiSolver solver, ObiRope rope)
{
// Create a rope
// Setup a blueprint for the rope:
var blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
blueprint.resolution = 0.65f;
blueprint.thickness = 0.45f;
blueprint.pooledParticles = 100;
Vector3 point = Vector3.zero;
blueprint.path.Clear();
int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
float mass = 1;
for (int i = 0; i < points.Length; i++)
{
if (i == 0 || i == points.Length - 1)
mass = .1f;
else
mass = .2f;
if( i == 0 )
{
point = rope.transform.InverseTransformPoint(points[i].position);
blueprint.path.AddControlPoint(point, -Vector3.zero, Vector3.zero, Vector3.up, mass, 0.5f, 1, filter, Color.white, "A");
}
Vector3 point2 = rope.transform.InverseTransformPoint(points[i].position);
Vector3 direction = (point2 - point) * 0.25f;
blueprint.path.AddControlPoint(point2, -direction, direction, Vector3.up, mass, 0.5f, 1, filter, Color.white, points[i].name);
}
blueprint.path.FlushEvents();
yield return StartCoroutine(blueprint.Generate());
rope.collisionMaterial = collisionMaterial;
rope.ropeBlueprint = blueprint;
// access the distance constraints currently simulated by the solver:
var solverConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Distance)
as ObiConstraints<ObiDistanceConstraintsBatch>;
int batches = solverConstraints.batches.Count;
for (int k = 0; k < batches; k++)
{
int cnt = solverConstraints.batches[k].constraintCount;
for (int i = 0; i < cnt; i++)
{
//solverConstraints.batches[k].restLengths[i] = length;
}
}
var obiRopeExtrudeRenderer = rope.GetComponent<ObiRopeExtrudedRenderer>();
// load the default rope section:
obiRopeExtrudeRenderer.section = Resources.Load<ObiRopeSection>("DefaultRopeSection");
obiRopeExtrudeRenderer.GetComponent<MeshRenderer>().material = material;
obiRopeExtrudeRenderer.GetComponent<ObiPathSmoother>().decimation = 0.1f;
obiRopeExtrudeRenderer.GetComponent<ObiPathSmoother>().smoothing = 3;
cursor = rope.AddComponent<ObiRopeCursor>();
cursor.cursorMu = 1;
cursor.sourceMu = 1;
obiRopeExtrudeRenderer.uvScale = new Vector2(2, 15);
obiRopeExtrudeRenderer.thicknessScale = 1.1f;
rope.distanceConstraintsEnabled = true;
rope.stretchingScale = 1f;
rope.stretchCompliance = 0f;
rope.bendCompliance = .1f;
PinRope(rope, points[0].GetComponent<ObiCollider>(), points[points.Length - 1].GetComponent<ObiCollider>(), new Vector3(0f, 0, 0), new Vector3(0f, 0, 0));
//RopeAttachment(rope, points[0].GetComponent<ObiCollider>(), points[points.Length - 1].GetComponent<ObiCollider>());
//AddDistanceConstrants(rope);
}
Code:
private void PinRope(ObiRope rope, ObiCollider bodyA, ObiCollider bodyB, Vector3 offsetA, Vector3 offsetB)
{
// Pin both ends of the rope (this enables two-way interaction between character and rope):
var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
pinConstraints.Clear();
var batch = new ObiPinConstraintsBatch();
batch.AddConstraint(rope.solverIndices[0], bodyA, offsetA, Quaternion.identity, 0, 0, float.PositiveInfinity);
batch.AddConstraint(rope.solverIndices[rope.activeParticleCount - 1], bodyB, offsetB, Quaternion.identity, 0, 0, float.PositiveInfinity);
batch.activeConstraintCount = 2;
pinConstraints.AddBatch(batch);
rope.SetConstraintsDirty(Oni.ConstraintType.Pin);
}