Posts: 29
Threads: 9
Joined: Jun 2024
Reputation:
0
Hi,
I have a shape with rigidboy attached to it. Rope is holding this shape. You can see the rope is stretching and pulling the shape all over the place. How to avoid the stretchiness and keep the shape stable ?
https://drive.google.com/file/d/1fLpU5D_...sp=sharing
I want something like in cut the rope
https://www.youtube.com/shorts/1kEYuIemwzo
Posts: 6,306
Threads: 24
Joined: Jun 2017
Reputation:
398
Obi Owner:
(07-06-2024, 09:51 AM)kripa1415 Wrote: I have a shape with rigidboy attached to it. Rope is holding this shape. You can see the rope is stretching and pulling the shape all over the place. How to avoid the stretchiness and keep the shape stable ?
Hi,
Not sure I understand your question. The video shows a rigidbody with seemingly no gravity, the rope passes trough one hole in it and pulls it around. This looks like the intended result for such a setup?
(07-06-2024, 09:51 AM)kripa1415 Wrote: I want something like in cut the rope
https://www.youtube.com/shorts/1kEYuIemwzo
Do you mean simply a rigidbody hanging from a rope? This is easily done using a dynamic particle attachment. See the "Crane", "Chains" or "FreigthLift" sample scenes for examples of dynamic attachments.
Posts: 29
Threads: 9
Joined: Jun 2024
Reputation:
0
Hi,
Yes no gravity kind of behaviour and rope stretch that was the problem. I set hanging object rigidbody y-axis position constraints locked. Rope was also stretching way beyond what I expected.
Now I solved it by releasing shape rigidbody y constraint and setting a base collider for it.
Overall gravity changed from y axis to z-axis to Vector3(0, 0, -9.81)
Set rope blue print mass to .2 while creating control points
Set hanging object mass to 100kg with z and x rotation constraint enabled
Adjusted the below rope params
Code: rope.distanceConstraintsEnabled = true;
rope.stretchingScale = .05f;
rope.stretchCompliance = 0.003f;
rope.bendCompliance = 1;
rope.maxBending = .5f;
Now its working!
https://drive.google.com/file/d/12RuGP6i...sp=sharing
Posts: 6,306
Threads: 24
Joined: Jun 2017
Reputation:
398
Obi Owner:
07-06-2024, 12:20 PM
(This post was last modified: 07-06-2024, 12:22 PM by josemendez.)
(07-06-2024, 12:05 PM)kripa1415 Wrote: Hi,
Yes no gravity kind of behaviour and rope stretch that was the problem. I set hanging object rigidbody y-axis position constraints locked. Rope was also stretching way beyond what I expected.
Now I solved it by releasing shape rigidbody y constraint and setting a base collider for it.
Overall gravity changed from y axis to z-axis to Vector3(0, 0, -9.81)
Set rope blue print mass to .2 while creating control points
Set hanging object mass to 100kg with z and x rotation constraint enabled
Adjusted the below rope params
Code: rope.distanceConstraintsEnabled = true;
rope.stretchingScale = .05f;
rope.stretchCompliance = 0.003f;
rope.bendCompliance = 1;
rope.maxBending = .5f;
Now its working!
https://drive.google.com/file/d/12RuGP6i...sp=sharing
Hi,
Good that it's working, but just wanted to point out that none of the parameters you set make any sense!
(07-06-2024, 12:05 PM)kripa1415 Wrote: Overall gravity changed from y axis to z-axis to Vector3(0, 0, -9.81)
Unity always uses Y as the vertical axis, both in 2D and 3D mode. Unless your game is oriented such that Z is its "down" vector (which will only happen if your camera is up in the air looking directly at the floor) gravity should be in the Y axis.
(07-06-2024, 12:05 PM)kripa1415 Wrote: Set rope blue print mass to .2 while creating control points
Set hanging object mass to 100kg with z and x rotation constraint enabled
Such a huge mass difference will make the rope stretch a lot more, not less. Generally in games you should strive for objects to not have a mass ratio larger than 1:10, yours is 1:500 (100/0.2). Either increase the rope's blueprint mass, or reduce the hanging object mass until either is not more than 10 times the other.
(07-06-2024, 12:05 PM)kripa1415 Wrote: Adjusted the below rope params
stretchingScale = 0.05f: tell the rope to compress to 5% of its initial length.
stretchCompliance = 0.003f: tell the rope to allow up to 30% of stretching.
bendCompliance = 1: tell the rope to not resist bending at all.
rope.maxBending = .5f: doesn't matter what you set, since bendCompliance = 1
These settings will result in a really short rope that stretches a lot, which I doubt is what you want. Typically you'd want the stretchingScale to be 1 and stretchCompliance to be 0 for a rope that doesn't stretch. Also, bendCompliance should be a lot lower unless you want to basically disable bending.
kind regards,
Posts: 29
Threads: 9
Joined: Jun 2024
Reputation:
0
07-06-2024, 12:45 PM
(This post was last modified: 07-06-2024, 12:46 PM by kripa1415.)
I tried your suggestion. setting stretching scale to 1 and stretchCompliance 0 causing unity to crash. Attached rope creation code snippet. Sometimes its working but extremely slow
frame by frame and rope also not in good shape. Attached video link here.
https://drive.google.com/file/d/1jC1ghSt...sp=sharing
Code: private IEnumerator CreateRope(ObiSolver solver, ObiRope rope)
{
// Create a rope
// Setup a blueprint for the rope:
var blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
blueprint.resolution = 0.65f;
blueprint.thickness = 0.45f;
blueprint.pooledParticles = 100;
Vector3 point = Vector3.zero;
blueprint.path.Clear();
int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
float mass = 1;
for (int i = 0; i < points.Length; i++)
{
if (i == 0 || i == points.Length - 1)
mass = .1f;
else
mass = .2f;
if( i == 0 )
{
point = rope.transform.InverseTransformPoint(points[i].position);
blueprint.path.AddControlPoint(point, -Vector3.zero, Vector3.zero, Vector3.up, mass, 0.5f, 1, filter, Color.white, "A");
}
Vector3 point2 = rope.transform.InverseTransformPoint(points[i].position);
Vector3 direction = (point2 - point) * 0.25f;
blueprint.path.AddControlPoint(point2, -direction, direction, Vector3.up, mass, 0.5f, 1, filter, Color.white, points[i].name);
}
blueprint.path.FlushEvents();
yield return StartCoroutine(blueprint.Generate());
rope.collisionMaterial = collisionMaterial;
rope.ropeBlueprint = blueprint;
// access the distance constraints currently simulated by the solver:
var solverConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Distance)
as ObiConstraints<ObiDistanceConstraintsBatch>;
int batches = solverConstraints.batches.Count;
for (int k = 0; k < batches; k++)
{
int cnt = solverConstraints.batches[k].constraintCount;
for (int i = 0; i < cnt; i++)
{
//solverConstraints.batches[k].restLengths[i] = length;
}
}
var obiRopeExtrudeRenderer = rope.GetComponent<ObiRopeExtrudedRenderer>();
// load the default rope section:
obiRopeExtrudeRenderer.section = Resources.Load<ObiRopeSection>("DefaultRopeSection");
obiRopeExtrudeRenderer.GetComponent<MeshRenderer>().material = material;
obiRopeExtrudeRenderer.GetComponent<ObiPathSmoother>().decimation = 0.1f;
obiRopeExtrudeRenderer.GetComponent<ObiPathSmoother>().smoothing = 3;
cursor = rope.AddComponent<ObiRopeCursor>();
cursor.cursorMu = 1;
cursor.sourceMu = 1;
obiRopeExtrudeRenderer.uvScale = new Vector2(2, 15);
obiRopeExtrudeRenderer.thicknessScale = 1.1f;
rope.distanceConstraintsEnabled = true;
rope.stretchingScale = 1f;
rope.stretchCompliance = 0f;
rope.bendCompliance = .1f;
PinRope(rope, points[0].GetComponent<ObiCollider>(), points[points.Length - 1].GetComponent<ObiCollider>(), new Vector3(0f, 0, 0), new Vector3(0f, 0, 0));
//RopeAttachment(rope, points[0].GetComponent<ObiCollider>(), points[points.Length - 1].GetComponent<ObiCollider>());
//AddDistanceConstrants(rope);
}
Code: private void PinRope(ObiRope rope, ObiCollider bodyA, ObiCollider bodyB, Vector3 offsetA, Vector3 offsetB)
{
// Pin both ends of the rope (this enables two-way interaction between character and rope):
var pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
pinConstraints.Clear();
var batch = new ObiPinConstraintsBatch();
batch.AddConstraint(rope.solverIndices[0], bodyA, offsetA, Quaternion.identity, 0, 0, float.PositiveInfinity);
batch.AddConstraint(rope.solverIndices[rope.activeParticleCount - 1], bodyB, offsetB, Quaternion.identity, 0, 0, float.PositiveInfinity);
batch.activeConstraintCount = 2;
pinConstraints.AddBatch(batch);
rope.SetConstraintsDirty(Oni.ConstraintType.Pin);
}
Posts: 6,306
Threads: 24
Joined: Jun 2017
Reputation:
398
Obi Owner:
07-06-2024, 03:31 PM
(This post was last modified: 07-06-2024, 03:34 PM by josemendez.)
(07-06-2024, 12:45 PM)kripa1415 Wrote: I tried your suggestion. setting stretching scale to 1 and stretchCompliance 0 causing unity to crash.
Those are the default values, so there must be something else causing the crash. There's a few things that don't quite add up:
- The rope is 0.45 meters thick (blueprint.thickness = 0.45f). That's a really thick rope, unless ropes in your game are hundreds of meters long I don't think that's intentional? Even if that's the case, a rope that's hundreds of meters long will behave as if it was moving in slow motion under normal earth gravity. It is advisable to stick to real-world units when dealing with physics, which means a board for a game of this type shouldn't be more than a couple meters in size.
- The tangent vectors are really strange. All control points have tangents that point from the first point in the rope to the current point (direction = (point2 - point) * 0.25f), which will make the rope kink along its path. The "point" variable is set for the first point, but never changed afterwards. This will only work somewhat ok if points.Length == 2, I don't know how many points are in it but seems like there's more than two? (since you check for the first and last points to change their mass)
- You're pinning the ends of the rope to the center of colliders (offsetA and offsetB set to zero) that may be colliding with the rope, since the code doesn't modify the collision filters of either the rope or the colliders. This will result in unphysical behavior as described in the manual: the collider wants the rope to be outside, but the attachment wants the rope to be inside, but it's impossible for an object to be simultaneously inside and outside something.
Other than these, the code looks fine. If the problems persist I think the only practical way forward would be for me to take a look at your project and see what's causing them, if possible send it to support(at)virtualmethodstudio.com so that I can diagnose these issues.
kind regards,
Posts: 29
Threads: 9
Joined: Jun 2024
Reputation:
0
Ok so what should be the recommended value for rope thickness. I tried .1, it looks very thin. Could you tell me the recommended values for blueprint thickness and rope extrude renderer thickness ?
Yes the tangent was an issue in code. Thanks for pointing out. I fixed that.
Also about the collider where rope going through knob colliders. Fixed that too.
Posts: 6,306
Threads: 24
Joined: Jun 2017
Reputation:
398
Obi Owner:
10-06-2024, 10:42 AM
(This post was last modified: 10-06-2024, 10:43 AM by josemendez.)
(10-06-2024, 08:39 AM)kripa1415 Wrote: Ok so what should be the recommended value for rope thickness. I tried .1, it looks very thin. Could you tell me the recommended values for blueprint thickness and rope extrude renderer thickness ?
There's no recommended values, you just need to pick a scale according to how you want the game to feel and apply it consistently to all objects in your game.
All units in Unity use the international system: distances/sizes are expressed in meters, time in seconds, mass in kilograms, etc. So if your ropes are 0.45 meters thick and they look ok, that means they must be several meters long (otherwise they'd look "chubby", i.e a rope that's half a meter thick and only one meter long) so your game board must also be huge. Unless you want the game to feel like you're moving huge chains around, things should be just smaller in general.
The same principle applies to any objects in Unity, by the way: if you make a car that weights 10 kg and it's 100 meters long, it will feel like it moves really slowly and it's very "floaty".
kind regards,
|