Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extend a rope when the attached object shot from a position
#6
(27-09-2022, 11:30 AM)lacasrac Wrote: 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

Hi,

I don't see any obvious issues with your code. When are you calling AddNewControlPoint()? Its name suggests that you're adding new control points to the blueprint at runtime, which isn't the intended use case. Blueprints are generated once and used to generate one (or more) ropes, setting the blueprint of a rope will essentially destroy the rope and re-create it from scratch using the particle and constraint data contained in the blueprint. This will make your rope "jump" to a new position and shape.

If you want to change the length of a rope at runtime, you should use cursor.ChangeLength().
Reply


Messages In This Thread
RE: Extend a rope when the attached object shot from a position - by josemendez - 28-09-2022, 07:19 AM