09
23

 

 

베지어 같은 복잡한게 필요한게 아니라

간단하게 부드럽게만 이어지면 되는 커브가 필요해짐.

 

레딧 : Make a Curved Line using Unity3d Line renderer
https://www.reddit.com/user/Sanketpanda/comments/f475vn/make_a_curved_line_using_unity3d_line_renderer/?utm_source=share&utm_medium=web2x

 

레퍼런스를 토대로 2포인트로도 작동하게 추가 작성함

당연히 테스트 코드라서 Update문쓰고 RemoveAt 쓰고 한거는 삭제해야됨.

public class LineTest : MonoBehaviour
{
    public LineRenderer linerenderer;

    public Transform startPoint;
    public Transform middlePoint_A;


    public Transform middlePoint_B;
    public Transform endPoint;

    public float vertexCount = 12;

    void Update()
    {
        var pointList = new List<Vector3>();
        Vector3 middlePoint = Vector3.Lerp(middlePoint_A.position, middlePoint_B.position, 0.5f);

        for (float ratio = 0; ratio <= 1; ratio += 1 / vertexCount)
        {
            var tangent1 = Vector3.Lerp(startPoint.position, middlePoint_A.position, ratio);
            var tangent2 = Vector3.Lerp(middlePoint_A.position, middlePoint, ratio);
            var curve = Vector3.Lerp(tangent1, tangent2, ratio);

            pointList.Add(curve);
        }

        pointList.RemoveAt(pointList.Count - 1);

        for (float ratio = 0; ratio <= 1; ratio += 1 / vertexCount)
        {
            var tangent1 = Vector3.Lerp(middlePoint, middlePoint_B.position, ratio);
            var tangent2 = Vector3.Lerp(middlePoint_B.position, endPoint.position, ratio);
            var curve = Vector3.Lerp(tangent1, tangent2, ratio);

            pointList.Add(curve);
        }

        linerenderer.positionCount = pointList.Count;
        linerenderer.SetPositions(pointList.ToArray());
    }
}

 

 

 

COMMENT