Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to give a tension to rope...
#1
Hi!
I wanna give a rope tense.

No longer give a length to rope

but when i move a rope's X transform, it getting more longger.....

What can i do...?

this is now. no tension, and draw is my expectaition.


Attached Files Thumbnail(s)
       
Reply
#2
Tension is defined as a force that increases strain. Strain is the ratio between the rope's rest length and its current length:

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

So if you want to increase strain, all you need to do is reduce the rope's rest length so that it is a percentage of the length between the points it is attached to. You can use a cursor to do that, like this:
Code:
cursor.ChangeLength(Vector3.Distance(attachmentA, attachmentB) * 0.6f); //rope is 40% shorter than the distance between its endpoints.

See: http://obi.virtualmethodstudio.com/manua...ursor.html
Reply
#3
It not changing a component but a code?

And than, what script?

I've searched all scripts using a keyword "cursor.ChangeLength" but, i only found ObiRopeCursor.cs ....

is it correct to change this cs file??
Reply
#4
(21-10-2021, 02:36 AM)sangku2000 Wrote: It not changing a component but a code?

Yes, you need to write some code for this to work.

(21-10-2021, 02:36 AM)sangku2000 Wrote: And than, what script?

Your own script, you need to write a script that calls cursor.ChangeLength(yourNewLength), where "cursor" is a variable of type ObiCursor.

(21-10-2021, 02:36 AM)sangku2000 Wrote: I've searched all scripts using a keyword "cursor.ChangeLength" but, i only found ObiRopeCursor.cs ....is it correct to change this cs file??

Im a bit confused by this question...you don't have to change ObiRopeCursor.cs or any other Obi script, if you do you can break the asset.

ChangeLength() is a public method exposed by ObiRopeCursor. You simply add a ObiRopeCursor component to your rope, and then call its ChangeLength() method in your own script. Take a look at the manual for an in-depth explanation and some sample code:
http://obi.virtualmethodstudio.com/manua...ursor.html

Note C# scripting skills are an absolute requirement to be able to use Obi, if you're unfamiliar with scripting/programming you'll find it very hard to use. See our FAQ:
http://obi.virtualmethodstudio.com/faq.html

Quote:Is scripting / coding required to use Obi?

For anything except the bare basics, yes. Obi is written in HPCS (high performance C#) and C++11, and it exposes a C# API. Obi deals with hundreds of particles and thousands of constraints every frame. These are exposed to you, the user, so learning how to write performant code is a prerequisite.
Reply
#5
Thanks for your advise! It perfectly work!

↓ this is my code!
public class RopeStrain : MonoBehaviour
{
    ObiRopeCursor cursor;
    ObiRope rope;

    public Transform attachmentStart;
    public Transform attachmentEnd;

    public float distanceRate = 0.45f;

    // Start is called before the first frame update
    void Start()
    {
        rope = GetComponent<ObiRope>();
        cursor = GetComponent<ObiRopeCursor>();
    }

    // Update is called once per frame
    void LateUpdate()
    {
        AdjustStrain();
    }

    private void AdjustStrain()
    {
        if (attachmentStart == null || attachmentEnd == null)
        {
#if UNITY_EDITOR
            Debug.Log("transform null...!!!");
#endif
            return;
        }
        cursor.ChangeLength(Vector3.Distance(attachmentStart.transform.position, attachmentEnd.transform.position) * distanceRate * Time.deltaTime);
   // length is adjusted by rate and time.
}

But.... I think self collider is seem to be not working...

I think i need to recalculate the element.. is right?


Attached Files Thumbnail(s)
   
Reply
#6
(22-10-2021, 04:07 AM)sangku2000 Wrote:         cursor.ChangeLength(Vector3.Distance(attachmentStart.transform.position, attachmentEnd.transform.position) * distanceRate * Time.deltaTime);
   // length is adjusted by rate and time.
}

But.... I think self collider is seem to be not working...


Do not multiply by Time.deltaTime
, it does not make any sense in this context. You're not changing the length over time, you're just setting it to a specific value. Multiplying by Time.deltaTime (which is a very, very small value, like 0.001) will set the length of your rope to be pretty much zero. This will result in a rope made of only two particles: one at each end. So no collisions will take place since there are no particles to collide with.


(22-10-2021, 04:07 AM)sangku2000 Wrote: I think i need to recalculate the element.. is right?

No need to Sonrisa
Reply
#7
cursor.ChangeLength(Vector3.Distance(attachmentStart.transform.position, attachmentEnd.transform.position) * distanceRate);    // rope adjust by rate.

This is new code...! (distanceRate is almost 0.1f)

But collider is not works now. Because of no particle impacted. (you've said)

I wanna make when ropes contact, they become a tangle. (now ropes doesn't impact each other)

In this situation, I need to recalculate rope's particles or make own particles??

I think i torture you....

Sorry... very very sorry....


Attached Files Thumbnail(s)
   
Reply
#8
(22-10-2021, 09:19 AM)sangku2000 Wrote: cursor.ChangeLength(Vector3.Distance(attachmentStart.transform.position, attachmentEnd.transform.position) * distanceRate);    // rope adjust by rate.

This is new code...! (distanceRate is almost 0.1f)

But collider is not works now. Because of no particle impacted. (you've said)

I wanna make when ropes contact, they become a tangle. (now ropes doesn't impact each other)

Add a ObiParticleRenderer component to your rope, make sure there's particles all along the rope. See:
http://obi.virtualmethodstudio.com/manua...ering.html

Assuming the rope does contain enough particles and there's no large gaps in between them, there's other issues that can prevent accurate collision detection:

- Make sure particle collision constraints are enabled in the solver: http://obi.virtualmethodstudio.com/manua...olver.html
- Make sure collision filters are properly set up. By default, ropes collide with everything, so unless you've changed this or you've reused a blueprint that had incorrect filter settings, it should work fine. For info on collision filters, see:http://obi.virtualmethodstudio.com/manual/6.2/collisions.html
- If your ropes are very tense, then gaps can appear in between particles, allowing ropes to pass trough each other. Using surface collisions can improve this. See: http://obi.virtualmethodstudio.com/manua...sions.html

You mention your distanceRate variable is 0.1, that will make the rope 10% of the distance between its ends and will likely open huge gaps in between particles. I don't think you need such large tension, any real-world rope or chain would snap under such strain. distanceRate is meant to be set to 0.8-0.99, or some value close to 1.

(22-10-2021, 09:19 AM)sangku2000 Wrote: In this situation, I need to recalculate rope's particles or make own particles??

No need to. Ropes will readily collide with each other, as long as they're correctly setup.

(22-10-2021, 09:19 AM)sangku2000 Wrote: Sorry... very very sorry....

No worries! answering questions is what I'm here for Sonrisa
Reply