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
#2
+1
Having similar problems, would love to know answer
Reply
#3
(21-09-2017, 03:40 AM)Parker Wrote: 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());
}

Hi!

You're not calling rope.AddToSolver() anywhere, so the rope is not being registered in the solver. Also, your UpdateRope() function is not called anywhere in the code, so the physics representation isn´t even being generated (unless you call it elsewhere, outside of this script). Keep in mind that GeneratePhysicRepresentationForMesh must only be called once, when initializing the rope. The name of your function (UpdateRope, as opposed to InitializeRope) seems to indicate you intend to call it every frame. Guiño

Also, the curve you've created has no points defined, so it won't generate any meaningful rope.

Take a look at Obi/Scripts/Utils/ObiRopeHelper.cs for a complete example on how to do this.

cheers!
Reply