12-07-2020, 12:16 AM
For context, I have a helicopter which will fly over a wood pallet and upon user input, 4 ropes will attach each corner of the pallet to the helicopter. These ropes are deactivated on start and the gameObjects are set active on user input.
I used the GrapplingHook.cs example as a reference. This video was the result.
Some observations:
- Upon connecting the ropes, the helicopters rotation was immediately locked to (0, 0, 0)
- The top end of the ropes seems to be constantly moving
- The pallet has a very strange gravity behavior
Code:
for (int i = 0; i < m_Ropes.Length; i++)
{
Transform anchorPoint = Pallet.GetAnchorPoints()[i];
// Create a new blueprint
ObiRopeBlueprint blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
blueprint.path.Clear();
blueprint.path.AddControlPoint(m_Ropes[i].transform.InverseTransformPoint(m_HelicopterAnchorPoints[i].position), m_HelicopterAnchorPoints[i].up, -m_HelicopterAnchorPoints[i].up, m_HelicopterAnchorPoints[i].up, 0.1f, 0.1f, 1, 1, Color.white, "Start");
blueprint.path.AddControlPoint(m_Ropes[i].transform.InverseTransformPoint(anchorPoint.position), anchorPoint.up, -anchorPoint.up, anchorPoint.up, 0.1f, 0.1f, 1, 1, Color.white, "End");
blueprint.path.FlushEvents();
await blueprint.Generate();
// Pin both ends of the rope
var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
var batch = pinConstraints.batches[0];
batch.AddConstraint(0, m_ObiCollider, Vector3.zero, Quaternion.identity);
batch.AddConstraint(blueprint.activeParticleCount - 1, Pallet.GetObiCollider(), anchorPoint.localPosition, Quaternion.identity);
batch.activeConstraintCount = 2;
m_Ropes[i].ropeBlueprint = blueprint;
// Enable the ropes
m_Ropes[i].gameObject.SetActive(true);
}
I also tried another approach using the ObiParticleAttachment scripts, I tried combinations of static and dynamic constraints but this was always the result: