Posts: 8
Threads: 3
Joined: Mar 2018
Reputation:
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
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
18-03-2018, 01:01 PM
(This post was last modified: 18-03-2018, 01:04 PM by josemendez.)
(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
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.
Posts: 8
Threads: 3
Joined: Mar 2018
Reputation:
1
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
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
18-03-2018, 02:33 PM
(This post was last modified: 18-03-2018, 02:35 PM by josemendez.)
(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
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)
Posts: 8
Threads: 3
Joined: Mar 2018
Reputation:
1
18-03-2018, 04:09 PM
(This post was last modified: 18-03-2018, 04:32 PM by usernameHed.)
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
Posts: 6,347
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
18-03-2018, 05:53 PM
(This post was last modified: 18-03-2018, 05:56 PM by josemendez.)
(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.
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
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,
|