Question by
suIly · Jul 01, 2021 at 05:04 PM ·
c#linerendererjoints
Draw Line Between Distance Joint 2D and Position
I'm trying to draw a line between two points. One is a solid point in space. The second is the position of a Distance Joint 2D. When I change the Anchor position of the Distance Joint 2D, the line renderer does not draw the line correctly. When I try to add the offset of the Anchor position to the position, it acts very weird. Here is my code.
public Transform point;
public LineRenderer line;
public DistanceJoint2D joint;
void Update()
{
line.positionCount = 2;
line.SetPosition(0, transform.position);
line.SetPosition(1, point.position + new Vector3(joint.anchor.x, joint.anchor.y, 0));
}
The blue circle is where the line renderer draws (with the offset of the anchor added to the position). The red circle is where I want the line renderer to draw.
capture.png
(51.0 kB)
Comment