21-09-2017, 03:40 AM
(This post was last modified: 21-09-2017, 03:37 PM by lidiamartinez.
Edit Reason: better title
)
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());
}
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());
}