Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Detect rope collision with raycast?
#1
Heya!
I have a line renderer which has a raycast following the rendered line.
I would like the rope to be cut where the raycast hits it (where they intersect eventually basically)

I currently have a script that cuts the rope at a hard-coded element for testing:

Code:
      using Obi;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.T))
        {
            ObiRope rope = GetComponent<ObiRope>();
            rope.Tear(rope.elements[35]);
            rope.RebuildConstraintsFromElements();
   
        }
    }

But how can I detect a specific element by raycast hit?
And additionally, for future reference, it would serve me well to know how to do the same for collider collisions with the rope as well!

I've tried digging through the forums and documentation, but I'm either not looking in the right place, or don't understand things that might be common sense (like what are "particle1" and "particle 2" inside of an element and such, the documentation only says they're ints but I'm not sure what they do).
If there is a more in-depth walkthrough I can follow to educate myself with, aside from the 4 videos on YouTube, I would love that!
Reply
#2
Hi there!

Code:
what are "particle1" and "particle 2" inside of an element and such, the documentation only says they're ints but I'm not sure what they do

As per the manual, a rope is essentially a list of points (particles) chained together. An element is just a line segment in between two particles. Particles are identified by their index in a solver.

From this you can conclude that "particle1" and "particle2" are the indices of the two particles at each end of the element.

Code:
But how can I detect a specific element by raycast hit?

You can't directly "raycast" against line segments because they have no volume or thickness. You can however cast a ray against particles (which is what the ObiParticlePicker utility component does), or treat segments as swept volumes (cylinders/capsules) and cast against that.

Note that there's no built-in raycast functions against either particles or elements, but it's trivial to write your own: casting against a particle is simply a point-segment distance test (you can use ObiUtils.ProjectPointLine or Vector3.Project for this) and casting against an element is just a segment-segment distance test.

Most of this is just general 3D math knowledge, so it isn't covered by the manual or youtube tutorials. All Obi does is expose a list of particles and their properties (positions, velocities, radius, etc) that you can get/set at any time (see:
http://obi.virtualmethodstudio.com/tutor...icles.html). What you do with this particle data is up to you.

Quote:it would serve me well to know how to do the same for collider collisions with the rope as well!

To detect collisions against colliders, you can subscribe to solver.OnCollision:
http://obi.virtualmethodstudio.com/tutor...sions.html
Reply