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)
{
lineRenderer.SetVertexCount(3);
bend_point = hit.point + (hit.normal / 20);
lineRenderer.SetPosition(1, bend_point);
is_bend = true;
}
lineRenderer.SetPosition(2, target.position);
}
else
{
if (is_bend)
{
lineRenderer.SetVertexCount(2);
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?