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 I've managed to work out Tearing pretty much, though it wasn't piece of cake Now I'm completely confused about how path AddControlPoint works and AddConstraints work.. I want to make straight rope which is attached to ragdoll player. But offsets are really painful to work with, I add slight offset to Constraints and it all messes up and when trying to match ControlPoint instead of playing around with offset - it's even more unpredictable. Any help with that? My implementation :
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.
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;
}