Simple wire/cable

I’m trying to make simple cable with raycast and line renderer, no need for physics.

Here is my current script:

void Update()
    lineRenderer.SetPosition(0, transform.position);
    RaycastHit hit;

    if (Physics.Linecast(transform.position, target.position, out hit))
        if (!is_bend)
            bend_point = hit.point + (hit.normal / 20);
            lineRenderer.SetPosition(1, bend_point);
            is_bend = true;
        lineRenderer.SetPosition(2, target.position);
        if (is_bend)
            is_bend = false;
        lineRenderer.SetPosition(1, target.position);


But this only allows one bend

Also the object can’t be moved too fast or the bend might happen in the middle of the wall.

Any suggestions how to make this better?

In Line 10 you set the Vertex Count to 3, use a higher Number then you should have more than yust one bend. Also you could try to change the option “Collision Detection” of both of your objects from “Discrete” to “Continuous”. This should result the problem you have where the wire gets stuck in the wall.
Hope this could help you even you asked this nearly 5 years ago :wink:
But there are always others searching for these problems so I hope I could help anyone out there.