Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Test if rope is tense, and extend it in code
#1
Hello, i have a rope attached on 2 player. I want to test in c# if the rope is tense enougth, and if so, extend the rope (when the player it a button for exemple).

I have found in GrapplingHook the way to extend the rope, with [ObiRopeCursor].ChangeLength([ObiRope].RestLength +- value;
Now, how can I test if the rope is more or less tense ? I could test the distance maybe...

I just bougth Obi rope, please be explicit

[Image: ezgif-4-e6bff1cec6.gif]
Reply
#2
(18-03-2018, 12:56 PM)usernameHed Wrote: Hello, i have a rope attached on 2 player. I want to test in c# if the rope is tense enougth, and if so, extend the rope (when the player it a button for exemple).

I have found in GrapplingHook the way to extend the rope, with [ObiRopeCursor].ChangeLength([ObiRope].RestLength +- value;
Now, how can I test if the rope is more or less tense ? I could test the distance maybe...

I just bougth Obi rope, please be explicit

[Image: ezgif-4-e6bff1cec6.gif]

Hi there,

You can calculate strain like this:

Code:
float strain = rope.CalculateLength()/rope.RestLength;

strain will be >1 if the rope is stretched, 1 if the rope has exactly its rest length, and < 1 if the rope is compressed.

To extend the rope, use the ObiCursor component as you just discovered. Just add it to the rope and call its ChangeLength(newLength) method. The "Crane" sample scene also uses it to extend/retract the crane, for instance.
Reply
#3
Oh thanks you ! what is the most cost efficient between a distance test, and this calculation ?
thanks you, this Rope asset is realy good btw Sonrisa
Reply
#4
(18-03-2018, 02:24 PM)usernameHed Wrote: Oh thanks you ! what is the most cost efficient between a distance test, and this calculation ?
thanks you, this Rope asset is realy good btw Sonrisa

A simple distance test is slightly faster, since this code calculates actual rope length.

However, a distance test will only work properly in the case of a rope that is completely straight when tense. If the rope is not straight (imagine a slingshot, in which the rope is tense but bent where it holds the projectile) then the distance test will underestimate rope tension. Keep this in mind when choosing your method! Sonrisa

Also, keep in mind that any performance gains obtained from choosing one or the other will be barely noticeable, if at all. (unless you have hundreds of ropes)
Reply
#5
Ok ! mmm I have one other little trouble:
I have set the pooledParticle to 50... but the moment I change the Length... like that:
cursor.ChangeLength(rope.RestLength + hookExtendRetractSpeed * Time.deltaTime);
then the variable pooledParticle drop to 9, 8, ... 0 (and not 49, 48, ... to 0...), so I have only 10 pooled Particle  to add... i don't know why i can't change it.
 
[Image: HCspbwQotAl_Capture.PNG][Image: HCspcbcIMAl_Capture2.PNG]


And one other thing... when i have my rope setup in inspector, if I want to grow the rope, and add more particle inside, how do I do ? Im' stuck with my 10 initial particle, and I want to grow it up, witout deleting and recreating the rope...
[Image: HCspgtToUOl_Capture3.PNG]

Thanks you again
Reply
#6
(18-03-2018, 04:09 PM)usernameHed Wrote: Ok ! mmm I have one other little trouble:
I have set the pooledParticle to 50... but the moment I change the Length... like that:
cursor.ChangeLength(rope.RestLength + hookExtendRetractSpeed * Time.deltaTime);
then the variable pooledParticle drop to 9, 8, ... 0 (and not 49, 48, ... to 0...), so I have only 10 pooled Particle  to add... i don't know why i can't change it.
 
[Image: HCspbwQotAl_Capture.PNG][Image: HCspcbcIMAl_Capture2.PNG]


And one other thing... when i have my rope setup in inspector, if I want to grow the rope, and add more particle inside, how do I do ? Im' stuck with my 10 initial particle, and I want to grow it up, witout deleting and recreating the rope...
[Image: HCspgtToUOl_Capture3.PNG]

Thanks you again

You need to reinitialize the rope after changing the amount of particles in the pool. Also to make its rest state shorter or larger, you cannot change the initial properties of the rope without re-initializing it. Just click Initialize again (make sure the rope path, ObiCatmullRomCurve in your case, has the correct shape/length you want the rope to have).

cheers,
Reply