Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Rope in runtime
#1
Unity is running.  Meaning this is real time.  The user will not be stopping the game and creating a rope, initializing it, and putting on handles, then re-start the game.

I want this to be done during runtime and with scripts.  When I use the code, the rope DOES NOT work, it has no physics attached.  How do you get it to work.

 ObiRope Rope;
 ObiSolver Solver;
 ObiCatmullRomCurve Curve;
 ObiRopeCursor Cursor;

 private void Awake()
 {
     if (Rope == null)
         Rope = gameObject.AddComponent<ObiRope>();

     if (Curve == null)
     {
         Curve = gameObject.AddComponent<ObiCatmullRomCurve>();
         Rope.ropePath = Curve;
     }
     if (Solver == null)
     {
         Solver = gameObject.AddComponent<ObiSolver>();
         Rope.Solver = Solver;
     }

     // Configure rope and solver parameters:
     Rope.SectionThicknessScale = 0.10f;
     Rope.resolution = 1f;
     Rope.BendingConstraints.stiffness = 0.2f;
     Rope.UVScale = new Vector2(1, 5);
     Rope.NormalizeV = false;
     Rope.UVAnchor = 1;

     Rope.RestLength = 10;
     Solver.distanceConstraintParameters.iterations = 15;
     Solver.pinConstraintParameters.iterations = 15;
     Solver.bendingConstraintParameters.iterations = 1;

     // Add a cursor to change rope length:
     Cursor = Rope.gameObject.AddComponent<ObiRopeCursor>();
     Cursor.rope = Rope;
     Cursor.normalizedCoord = 0;
     Cursor.direction = true;
 }


public void InitRope()
{
    Rope.UpdateVisualRepresentation();
}

private IEnumerator CreateRope()
{
    yield return Rope.GeneratePhysicRepresentationForMesh();
}

public void UpdateRope()
{
    StartCoroutine(CreateRope());
}
Reply


Messages In This Thread
Creating Rope in runtime - by Parker - 21-09-2017, 03:40 AM
RE: Creating Rope in runtime - by phoberman - 15-12-2017, 02:24 AM
RE: Creating Rope in runtime - by josemendez - 15-12-2017, 11:55 AM