Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with RigitBody
#1
[Image: 2024-03-06-111633.png]
[Image: 2024-03-06-112345.png]
The problem is as follows: I have a code that creates a control point in the middle of the rope, then I create an attachment on the rope and attach it to the attraction point inside the object that I want to move with this rope. Since the attraction point itself is attached to the main RigidBody (box) through a fixedJoint, it starts to press it into other colliders, ignoring collisions, because the weight of the ControlPoint presses from above so strongly that it ignores the mass of the main object (box). However, I need to achieve an effect where pulling the attraction object would be difficult depending on its weight, and the lighter it is, the easier it is to pull it by moving the control point on the other end of the rope.

Code:
        public void AttachRopeAtCurrentCenter(AttractionObject attractionObject)
        {
            _blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();

            var fatherConnectionPoint = _playersContainer[PlayerCharacter.Father].ConnectionPoint;
            var sonConnectionPoint = _playersContainer[PlayerCharacter.Son].ConnectionPoint;
            Vector3 father = ObiRope.transform.InverseTransformPoint(fatherConnectionPoint.position);
            Vector3 center = ObiRope.transform.InverseTransformPoint(attractionObject.AttractionPoint.position);
            Vector3 son = ObiRope.transform.InverseTransformPoint(sonConnectionPoint.position);
            int allLayers = (1 << 16) - 1;
            int excludeLayer15 = ~(1 << 15);
            int finalMask = allLayers & excludeLayer15;

            int filter = ObiUtils.MakeFilter(finalMask,
                1);

            _blueprint.path.Clear();

            _blueprint.path.AddControlPoint(father,
                -father.normalized,
                father.normalized,
                Vector3.zero,
                _controlPointsMass,
                _controlPointsMass,
                1,
                filter,
                Color.white,
                "start");

            _blueprint.path.AddControlPoint(center,
                -center.normalized,
                center.normalized,
                Vector3.zero,
                _controlPointsMass,
                _controlPointsMass,
                1,
                filter,
                Color.white,
                "center");

            _blueprint.path.AddControlPoint(son,
                -son.normalized,
                son.normalized,
                Vector3.zero,
                0.1f,
                0.1f,
                1,
                filter,
                Color.white,
                "end");

            _blueprint.path.FlushEvents();
            _blueprint.Generate();
            ObiRope.ropeBlueprint = _blueprint;


            var pinConstraints = ObiRope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
            pinConstraints.Clear();
            var batch = new ObiPinConstraintsBatch();
            _centerOfRopePointCollider.transform.position = attractionObject.AttractionPoint.position;

            if (attractionObject.Type == AttractionObject.AttractionPointType.Kinematic)
                _centerOfRopePointObiRigidbody.kinematicForParticles = true;


            batch.AddConstraint(ObiRope.solverIndices[0],
                _fatherConnectionPointObiCollider,
                Vector3.zero,
                Quaternion.identity,
                0,
                0,
                float.PositiveInfinity);

            batch.AddConstraint(ObiRope.solverIndices[_blueprint.activeParticleCount - 1],
                _sonConnectionPointObiCollider,
                Vector3.zero,
                Quaternion.identity,
                0,
                0,
                float.PositiveInfinity);

            var attachment = ObiRope.GetComponent<ObiParticleAttachment>();
            attachment.particleGroup = ObiRope.ropeBlueprint.groups[1];

            if (attractionObject.Type == AttractionObject.AttractionPointType.Kinematic)
            {
                attachment.target = attractionObject.transform;
                attachment.attachmentType = ObiParticleAttachment.AttachmentType.Static;
            }
            else
            {
                attachment.target = attractionObject.AttractionPoint;
                attachment.attachmentType = ObiParticleAttachment.AttachmentType.Dynamic;
            }
            batch.activeConstraintCount = 2;
            pinConstraints.AddBatch(batch);
            ObiRope.SetConstraintsDirty(Oni.ConstraintType.Pin);
        }
Reply
#2
Hi,

I'm not entirely sure I understood your description: you one rigidbody attached to the rope via a ObiParticleAttachment, and a second rigidbody attached to the first one via a FixedJoint. Is this correct?

If you're using a dynamic attachment -as opposed to a static one, which ignores mass- this should work fine: the attachment will take into account the mass of the rigidbody it is attached to, and the FixedJoint will take into account the mass of both rigidbodies. Depending on the mass of the second (main) rigidbody, it will be easier or harder to pull it around.

This is a test I've made using your setup (the way I understood it, at least):
Reply
#3
(06-03-2024, 11:56 AM)Хосемендес Wrote: Привет,

я не совсем уверен, что понял ваше описание: вы одно твердое тело прикреплены к веревке через ObiParticleAttachment, а второе твердое тело прикреплено к первому через фиксированное соединение. Это верно?

Если вы используете динамическое вложение, а не статическое, которое игнорирует массу, это должно работать нормально: вложение будет учитывать массу твердого тела, к которому оно прикреплено, а фиксированное соединение будет учитывать массу. обоих твердых тел. В зависимости от массы второго (основного) твердого тела его будет легче или труднее тянуть.

Это тест, который я провел, используя вашу настройку (по крайней мере, так, как я ее понял):


[Image: 2024-03-06-122909.png]




Everything is a little more complicated, I have two default attachments for two players. Between them, in the middle in Play mode, I create a third control point "Dinamic" from the code and attach it to the AttractionPoint (based on your "Hook" script). Sorry if everything is too confusing, I think I've reached a dead end.
Reply
#4
(06-03-2024, 12:32 PM)Alexander34 Wrote: [Image: 2024-03-06-122909.png]




Everything is a little more complicated, I have two default attachments for two players. Between them, in the middle in Play mode, I create a third control point "Dinamic" from the code and attach it to the AttractionPoint (based on your "Hook" script). Sorry if everything is too confusing, I think I've reached a dead end.

This seems to be the same thing I tested, the only difference is that the dynamic attachment is in the middle of the rope instead of one end?

Would it be possible for you to share this scene with me (by sending it to support(at)virtualmethodstudio.com) so that I can take a closer look?
Reply
#5
(06-03-2024, 01:36 PM)josemendez Wrote: This seems to be the same thing I tested, the only difference is that the dynamic attachment is in the middle of the rope instead of one end?

Would it be possible for you to share this scene with me (by sending it to support(at)virtualmethodstudio.com) so that I can take a closer look?

I resolved it in the following way. I retained only one collider with a mesh child object attached to the AttractionObject. Then, I shifted the child object downward along the y-axis by -0.5. Consequently, the Pivot of the main object ended up where the Attraction Point used to be. And now it functions properly.[/size]
[Image: 2024-03-06-171154.png]

I didn’t bother to figure out why it works this way, but obviously there are problems with the child RigitBody and there may be a fixed joint.
Reply