Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tons of problems trying to simulate simple rope without elasticity
#12
(19-01-2022, 02:58 AM)Romahaaa Wrote: Oh, sorry, I didn't click "Add attachement". Here it is.

Regarding pin constraints - even setting it to 100 didn't help. There is still a gap between paperclip and rope end. Paperclip mass is just  0.01.


No, it's not about physics interpolation because it switched off. It's easier to check the scene I attached instead of describing it. You may see the cylinder collider under the paperclip and while the paperclip position not changed (at least visually) in static state, paperclip collider triggers with that cylinder collider

Hi there,

Thanks! Took a look at the updated scene, seems the culprit is just the scale at which simulation is performed. The gap between the rope and the clip is about 2 millimeters wide (0.002 world space units). This is caused by numerical accuracy within the solver: many operations have a certain accuracy limit (epsilon) to avoid division by zero. Furthermore, Unity's physics engine is velocity-based. Obi is position-based, which means adjustments to meet constraints are done at the positional level, this grants it unconditional stability since all calculations are independent of the timestep size. However when applying adjustments to Unity rigidbodies, it's not possible to directly set the position of a point in the rigidbody: it must be indirectly adjusted by applying an impulse to it. Both the epsilon and the fact that rigidbody positions are indirectly adjusted trough velocity corrections contribute to this.

There's a way to get around it though: hook to the actor's OnInterpolate event, and set the renderable particle position to the attach point on the object. This does not affect physics, but will visually close the gap with 100% accuracy as we're just copying the attachment position to the particle every frame before rendering. I've attached a modified ObiParticleAttachment.cs script that does this. In case you're interested, the code looks like this:

Code:
private void M_Actor_OnInterpolate(ObiActor actor)
        {
            if (enabled && m_AttachmentType == AttachmentType.Dynamic && m_Actor.isLoaded && isBound)
            {

                var solver = m_Actor.solver;

                var actorConstraints = m_Actor.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;

                if (actorConstraints != null && pinBatch != null)
                {
                    int pinBatchIndex = actorConstraints.batches.IndexOf(pinBatch);
                    if (pinBatchIndex >= 0 && pinBatchIndex < actor.solverBatchOffsets[(int)Oni.ConstraintType.Pin].Count)
                    {
                        for (int i = 0; i < pinBatch.activeConstraintCount; i++)
                        {
                            var attachPoint = pinBatch.pinBodies[i].owner.transform.TransformPoint(pinBatch.offsets[i]);

                            // Force the visual position of the particle to match the collider's place:
                            solver.renderablePositions[pinBatch.particleIndices[i]] = solver.transform.InverseTransformPoint(attachPoint);
                        }
                    }
                }
            }
        }

You could also do this on a separate component, but having it built-in in the attachment component is probably more comfortable.This will get rid of the gap for good:

[Image: ayIVZsW.gif]

At this size though, even the slightest numerical inaccuracy becomes large enough to be noticed. You will also encounter issues with depth testing, shadows, vertex shimmering when away from the world origin, and a whole other lot of problems - that can be alleviated by adjusting camera far/near planes, shadow biases, using camera-relative rendering, using a very small physics timestep... but will make your life harder than it needs to be.

As an experiment, I created a stack of 3 2x2x2 millimeter boxes, but PhysX is unable to accurately perform collision detection. The boxes clip trough each other on the first frame and the stack immediately falls. Once on the floor, they start to slide around.

[Image: pEfmD9g.png]
[Image: 1XTjKuM.png]

I'd guess the issue with the trigger also stems from this. If your game revolves around very small objects, I'd just fake the scale: Make everything larger in world units, and rely on relative sizes between objects to give the player the impression they're smaller. For instance if you have a paperclip and a human character, make both x 5 larger than their usual size. Since the player can only judge the size of the clip by comparing it to the human, it will appear to be very small even if it's actually not that small.

Let me know if I can help you in any way.

kind regards,


Attached Files
.cs   ObiParticleAttachment.cs (Size: 21.5 KB / Downloads: 11)
Reply


Messages In This Thread
RE: Tons of problems trying to simulate simple rope without elasticity - by josemendez - 19-01-2022, 10:35 AM