17-06-2021, 03:41 PM
Hello, I've been working on a bridge-building project similar to Polybridge. I stumbled upon your asset when I wanted to figure out how to implement cables for the bridges. This means they need to be created in runtime with a custom length and span between two given points.
I have been able to create particle attachments, I've made sure the connected objects have obiColliders and rigidBodies on them but my main problem is getting the ropes to visually span the distance between the points. I don't know if it's a obiRopeCursor problem where I just need to adjust the length, or if I need to insert control points into the rope's path.
Here's my code for instantiating the rope and creating the attachment points. GameManager.AllConnections is a dictionary that takes a Vector3 as a key with an object as the value.
And here is a video of what it looks like in-game: Video
I have been able to create particle attachments, I've made sure the connected objects have obiColliders and rigidBodies on them but my main problem is getting the ropes to visually span the distance between the points. I don't know if it's a obiRopeCursor problem where I just need to adjust the length, or if I need to insert control points into the rope's path.
Here's my code for instantiating the rope and creating the attachment points. GameManager.AllConnections is a dictionary that takes a Vector3 as a key with an object as the value.
Code:
ObiRope newRope = Instantiate(lightCablePrefab, (StartPosition + EndPosition) / 2, Quaternion.FromToRotation(new Vector3(1, 0, 0), EndPosition - StartPosition)).GetComponent<ObiRope>();
ObiParticleAttachment attachment1 = newRope.gameObject.AddComponent(typeof(ObiParticleAttachment)) as ObiParticleAttachment;
ObiParticleAttachment attachment2 = newRope.gameObject.AddComponent(typeof(Obi.ObiParticleAttachment)) as ObiParticleAttachment;
newRope.path.InsertControlPoint(newRope.path.ControlPointCount - 1, StartPosition, (StartPosition - EndPosition).normalized, (EndPosition - StartPosition).normalized, Vector3.up, 0.1f, 0.1f, 0.2f, 0, Color.red, "New Start");
newRope.path.InsertControlPoint(newRope.path.ControlPointCount - 1, EndPosition, (EndPosition - StartPosition).normalized, (StartPosition - EndPosition).normalized, Vector3.up, 0.1f, 0.1f, 0.2f, 0, Color.red, "New End");
attachment1.target = GameManager.AllConnections[StartPosition].transform;
attachment1.attachmentType = Obi.ObiParticleAttachment.AttachmentType.Dynamic;
attachment1.particleGroup = newRope.blueprint.groups[1];
attachment2.target = GameManager.AllConnections[EndPosition].transform;
attachment2.attachmentType = Obi.ObiParticleAttachment.AttachmentType.Dynamic;
attachment2.particleGroup = newRope.blueprint.groups[2];
ObiRopeCursor cursor = newRope.GetComponent<ObiRopeCursor>();
cursor.ChangeLength(Vector3.Magnitude(StartPosition - EndPosition));
newRope.transform.parent = StaticVars.vars.ObiSolver;
And here is a video of what it looks like in-game: Video