Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extend a rope when the attached object shot from a position
#5
(27-09-2022, 08:05 AM)josemendez Wrote: Attaching to a rag doll leg is no different from attaching to any other object: use a dynamic particle attachment. See:
http://obi.virtualmethodstudio.com/manua...ments.html

If the rope intersects the leg, take special care to ensure the rope is not colliding against it, otherwise instabilities will arise as the rope is simultaneously told to be inside and outside the leg collider. This is described in the above link, in the "Attachments inside colliders" section.

kind regards,


Here is my updated code, came after the floor reached the floor

Code:
private ObiParticleAttachment _lastAttachment;
private GameObject _lastAttachmentGo;

  public void AddNewControlPoint(Transform t, GameObject ropeEnd) {
            if (_lastAttachmentGo == null) {
                _lastAttachmentGo = t.gameObject;
               
                ropeEnd.GetComponent<CapsuleCollider>().enabled = false;

                var coll = _lastAttachmentGo.AddComponent<ObiCollider>();
                if (collideWithEverything)
                    coll.Filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
                else
                    coll.Filter = ObiUtils.MakeFilter(ObiUtils.CollideWithNothing, 0);

                var pos = new Position();
                pos.Transform = t;
                pos.AttachmentType = ObiParticleAttachment.AttachmentType.Dynamic; 
                positions.Add(pos);

                var i = positions.Count - 1;

                var p = positions[i].Transform.position;

                var startPositionLS = transform.InverseTransformPoint(p);
                var tangentLS = Vector3.down;

                if (i + 1 < positions.Count)
                {
                    var nextP = positions[i + 1].Transform.position;
                    var endPositionLS = transform.InverseTransformPoint(nextP);
                    tangentLS = (endPositionLS - startPositionLS).normalized;
                }

                var filter = 1;
                if (collideWithEverything)
                    filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
                    //CollideWithNothing
                else
                    filter = ObiUtils.MakeFilter(ObiUtils.CollideWithNothing, 0);

                var blueprint = rope.ropeBlueprint;

                blueprint.path.AddControlPoint(startPositionLS, -tangentLS, tangentLS, Vector3.up, mass,
                    mass, 1,
                    filter, Color.white, "ctrl_" + i);

                blueprint.path.FlushEvents();
                blueprint.GenerateImmediate();

                rope.ropeBlueprint = blueprint;

                //               
                Debug.Log("AddNewControlPoint i " + i + " " + positions.Count);
                _lastAttachment = gameObject.AddComponent<ObiParticleAttachment>();
                _lastAttachment.target = positions[i].Transform;
                _lastAttachment.attachmentType = positions[i].AttachmentType;
                _lastAttachment.particleGroup = blueprint.groups[i];
            }
        }



Transform t is the ragdoll leg. RopeEnd is just for visualization

collideWithEverything is always false

What is the probleme here? The rope jumping back again
Reply


Messages In This Thread
RE: Extend a rope when the attached object shot from a position - by lacasrac - 27-09-2022, 11:30 AM