09-09-2020, 09:11 AM
(08-09-2020, 09:16 AM)josemendez Wrote: That page is for a previous version, 4.X to be exact, as evidenced by the URL:Hey
http://obi.virtualmethodstudio.com/tutorials_4/scriptingconstraints.html
The docs for the current version are always at:
http://obi.virtualmethodstudio.com/tutorials/
You can't get the element right away from the collision, as the underlying physics engine is unaware of what an element is, it only works with particles. Each element is an "edge" between two particles (element.particle1 and element.particle2), so you should search for the element that contains the particle you want to tear. These are solver indices (as opposed to actor indices), so you can directly look trough all elements for the particle reported by contact.particle. Once you find an element such that element.particle1 == contact.particle, you can pass that element to rope.Tear() and skip all other elements.
Manual tearing isn't well documented though (on my TODO list), most info you can find is by looking at the API docs, but should be pretty straightforward once you understand the things involved. Let me know if you need help with actual code.
![Sonrisa Sonrisa](https://obi.virtualmethodstudio.com/forum/images/smilies/smile.png)
![Gran sonrisa Gran sonrisa](https://obi.virtualmethodstudio.com/forum/images/smilies/biggrin.png)
![Gran sonrisa Gran sonrisa](https://obi.virtualmethodstudio.com/forum/images/smilies/biggrin.png)
Code:
private IEnumerator CreateRope()
{
blueprint.path.Clear();
Vector3 targetPos = endPoint.position;
targetPos.y += 1f; // this for some reason shifts rope to x axis, when changing this value to other number then 1 - it shifts rope to y axis
blueprint.path.AddControlPoint(startPoint.position, Vector3.zero, Vector3.zero, Vector3.down, 0.1f, 0.1f, 1, 1, Color.white, "Hook start");
blueprint.path.AddControlPoint(targetPos, Vector3.zero, Vector3.zero, Vector3.down, 0.1f, 0.1f, 1, 1, Color.white, "Hook end");
blueprint.path.FlushEvents();
yield return blueprint.Generate();
var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
var batch = pinConstraints.batches[0];
batch.AddConstraint(0, startPoint.GetComponent<ObiCollider>(), Vector3.zero, Quaternion.identity);
batch.AddConstraint(blueprint.activeParticleCount - 1, endPoint.GetComponent<ObiColliderBase>(), Vector3.zero, Quaternion.identity);
batch.activeConstraintCount = 2;
rope.ropeBlueprint = blueprint;
rope.GetComponent<MeshRenderer>().enabled = true;
}