Posts: 6,322
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
10-06-2020, 08:38 PM
(This post was last modified: 10-06-2020, 08:45 PM by josemendez.)
(10-06-2020, 08:12 PM)Kifwat Wrote: Okey that sounds good, but I think that will be easy just if the rope is straight and the two cubes move in a straight movement, so we can add edit the rope's length depending on the distance between the two cubes, but how can we do that when the rope is foldable and not straight? I mean in case the rope is stretched by other object's movement, how can we track that and then increase its length depending on the contact with the other object?
I don’t get your question. The length of a rope is always the same regardless of it being straight, rolled up or folded in any position.
If you want to get the actual rope length including stretching -instead of its rest length-, just call rope.CalculateLength(). This will return the current rope length accounting for any stretching: the sum of all distances between each particle and the next one, so it’s really just the same as the case when the rope is straight. Check the API docs, and the crane example.
Posts: 20
Threads: 7
Joined: May 2020
Reputation:
0
(10-06-2020, 08:38 PM)josemendez Wrote: I don’t get your question. The length of a rope is always the same regardless of it being straight, rolled up or folded in any position.
If you want to get the actual rope length including stretching -instead of its rest length-, just call rope.CalculateLength(). This will return the current rope length accounting for any stretching: the sum of all distances between each particle and the next one, so it’s really just the same as the case when the rope is straight. Check the API docs, and the crane example.
I mean after calculating the rope length including the stretching, how can I add particles between the ones who has a big distance between them (because of the stretching), to make the rope's particles always have the same distance between them, despite of the rope's length. Hope you understand what I mean
Posts: 6,322
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
10-06-2020, 09:09 PM
(This post was last modified: 10-06-2020, 09:11 PM by josemendez.)
(10-06-2020, 08:55 PM)Kifwat Wrote: I mean after calculating the rope length including the stretching, how can I add particles between the ones who has a big distance between them (because of the stretching), to make the rope's particles always have the same distance between them, despite of the rope's length. Hope you understand what I mean
I don’t think I get it... no matter how the total length of the rope is distributed across particle constraints (some might be very stretched, other not so much), the total rope length is the same. When increasing the length of the rope using a cursor, new constraints will always have the same rest length. This is taken care of automatically, I believe you’re overcomplicating things a lot: just call cursor.ChangeLength(new length) when the value returned by rope.CalculateLength() exceeds the rest length by some threshold. Pseudocode:
float length = rope.CalculateLength();
If (length > rope.restLength + threshold)
cursor.ChangeLength(length);
Posts: 20
Threads: 7
Joined: May 2020
Reputation:
0
10-06-2020, 09:41 PM
(This post was last modified: 10-06-2020, 10:05 PM by Kifwat.)
(10-06-2020, 09:09 PM)josemendez Wrote: I don’t think I get it... no matter how the total length of the rope is distributed across particle constraints (some might be very stretched, other not so much), the total rope length is the same. When increasing the length of the rope using a cursor, new constraints will always have the same rest length. This is taken care of automatically, I believe you’re overcomplicating things a lot: just call cursor.ChangeLength(new length) when the value returned by rope.CalculateLength() exceeds the rest length by some threshold. Pseudocode:
float length = rope.CalculateLength();
If (length > rope.restLength + threshold)
cursor.ChangeLength(length);
Thanks for the code, the issue now is that the added particles stay fixed and didn't moves, and the code work for just one or two moves, and after that I got this error:
IndexOutOfRangeException: Index was outside the bounds of the array.
Obi.ObiActor.SwapWithFirstInactiveParticle (System.Int32 actorIndex) (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:420)
Obi.ObiActor.ActivateParticle (System.Int32 actorIndex) (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:434)
Obi.ObiRopeCursor.AddParticleAt (System.Int32 index) (at Assets/Obi/Scripts/RopeAndRod/Actors/ObiRopeCursor.cs:118)
Obi.ObiRopeCursor.ChangeLength (System.Single newLength) (at Assets/Obi/Scripts/RopeAndRod/Actors/ObiRopeCursor.cs:203)
RopeScript.Update () (at Assets/Scripts/RopeScript.cs:28)
Can you make a quick video on this please, because I'm stuck on this all the day
Beside that, I think the perfect way to solve my problem - If it were possible- is to increase the number of particles to a higher number, but it's not possible to increase the resolution to more than 1.
Posts: 6,322
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
11-06-2020, 08:13 AM
(This post was last modified: 11-06-2020, 08:13 AM by josemendez.)
(10-06-2020, 09:41 PM)Kifwat Wrote: Thanks for the code, the issue now is that the added particles stay fixed and didn't moves, and the code work for just one or two moves, and after that I got this error:
Can you make a quick video on this please, because I'm stuck on this all the day
Make sure you set its source mu to a location in the rope where particles aren't fixed. If you keep it at zero and the particle at zero is fixed, the cursor will take it as source and instantiate fixed particles.
Both the cursor mu and the source mu are normalized values: 0 means start of the rope, 1 means end of the rope. The source is the place where particles will be copied from, and the cursor the place where they will be added.
(10-06-2020, 09:41 PM)Kifwat Wrote: Beside that, I think the perfect way to solve my problem -If it were possible- is to increase the number of particles to a higher number, but it's not possible to increase the resolution to more than 1.
It is possible to set any resolution, it's only that the max resolution value is capped at 1 in the interface so that people don't go crazy with it, the need to use values higher than 1 is very rare as it gives diminishing returns. The more particles you have in your rope, the larger the performance impact, and the slower the simulation will converge. You will need more substeps to achieve the same stiffness, because there are more constraints in the system now.
To go past a resolution of 1, open up ObiRopeBlueprintBase.cs and comment out the [Range(0, 1)] attribute at line 15. You will now be able to enter any resolution value.
|