Help Test if rope is tense, and extend it in code - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help Test if rope is tense, and extend it in code (/thread-490.html) |
Test if rope is tense, and extend it in code - usernameHed - 18-03-2018 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 RE: Test if rope is tense, and extend it in code - josemendez - 18-03-2018 (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). 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. RE: Test if rope is tense, and extend it in code - usernameHed - 18-03-2018 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 RE: Test if rope is tense, and extend it in code - josemendez - 18-03-2018 (18-03-2018, 02:24 PM)usernameHed Wrote: Oh thanks you ! what is the most cost efficient between a distance test, and this calculation ? 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! 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) RE: Test if rope is tense, and extend it in code - usernameHed - 18-03-2018 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. 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... Thanks you again RE: Test if rope is tense, and extend it in code - josemendez - 18-03-2018 (18-03-2018, 04:09 PM)usernameHed Wrote: Ok ! mmm I have one other little trouble: 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, |