Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  How to attach a GameObject to a rope from script?
#1
Hi,

There is a rope and some objects in a table. I drag the rope and move, when the rope collide with an object, the object should be attached to the rope.
How should I implement this?

My idea is in the collision event of the rope and objects, I create a ControlPoint in the path of the rope, and a ObiParticleAttachment, and set the control point to the ObiParticleAttachment.

Code:
particlePos = solver.particleToActor[contact.bodyA].actor.transform.position;

int particleIndex = blueprint.path.ControlPointCount;
Vector3 localHit = rope.transform.InverseTransformPoint(particlePos);
blueprint.path.AddControlPoint(localHit, -localHit.normalized, localHit.normalized, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "Control point");
blueprint.path.FlushEvents();
yield return blueprint.Generate();
Code:
ObiParticleAttachment attachment = rope.gameObject.AddComponent<ObiParticleAttachment>();
attachment.target = targetGrain;
attachment.particleGroup = blueprint.groups[particleIndex];
attachment.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
attachment.compliance = 0;


But there are something wrong:
1. particlePos is the position of the rope not the collided point.
2. Got error "The particle group 'Control point' references a particle that does not exist in the actor 'Obi Rope'."

How do I implement this functionality?
Thanks in advance.
Reply


Messages In This Thread
How to attach a GameObject to a rope from script? - by wakin001 - 08-06-2021, 03:56 PM