- Home /
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)
{
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?
While not as simple, this video tutorial shows how to make a rope. At the end of the video, they suggest to go for the paid Obi Rope asset if you need more physically extensive simulations.
Answer by zweiler1 · Feb 13, 2020 at 02:36 PM
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 ;) But there are always others searching for these problems so I hope I could help anyone out there.
Your answer
Follow this Question
Related Questions
Linecast questions. 1 Answer
Raycasting along line renderer width 1 Answer
Problem with raycast vertical 1 Answer
Help with Raycast C# 0 Answers