gpt4 book ai didi

c# - unity中如何通过Line Renderer得到流畅的线条?

转载 作者:行者123 更新时间:2023-12-05 03:55:48 24 4
gpt4 key购买 nike

line renderer checked, tolerance 1, corner vertices and end cap vertices 5, alignment: view, texture mode: stretch,  shadow bias: .5

Image of Lines taken from unity

通过鼠标移动画出的线,但曲线一点也不光滑,这种线看起来很丑。我试图更改线渲染器的设置但没有任何帮助。我被困在这里,需要一些支持......下面我也提到了代码...... enter image description here

public GameObject linePrefab;
public GameObject currentLine;
public LineRenderer lineRenderer;
public EdgeCollider2D edgeCollider;
public List<Vector2> fingerPosition;
void Update()
{
if(Input.GetMouseButtonDown(0))
{
CreateLine();
}
if(Input.GetMouseButton(0))
{
Vector2 tempFingerPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if(Vector2.Distance(tempFingerPos, fingerPosition[fingerPosition.Count -1]) > 0.1f)
{
UpdateLine(tempFingerPos);
}
}

}
void CreateLine()
{
currentLine = Instantiate(linePrefab, Vector3.zero, Quaternion.identity);
lineRenderer = currentLine.GetComponent<LineRenderer>();
edgeCollider = currentLine.GetComponent<EdgeCollider2D>();
fingerPosition.Clear();
fingerPosition.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
fingerPosition.Add(Camera.main.ScreenToWorldPoint(Input.mousePosition));
lineRenderer.SetPosition(0, fingerPosition[0]);
lineRenderer.SetPosition(1, fingerPosition[1]);
edgeCollider.points = fingerPosition.ToArray();
}
void UpdateLine(Vector2 newFingerPos)
{
fingerPosition.Add(newFingerPos);
lineRenderer.positionCount++;
lineRenderer.SetPosition(lineRenderer.positionCount - 1, newFingerPos);
}

最佳答案

您可以尝试在绘制线条时使用一种算法来平滑线条,例如 Catmull-rom 或 Bezier,但有效地使其看起来更平滑的唯一方法是添加更多点。

Here is a SO question that can help with CR splines

关于c# - unity中如何通过Line Renderer得到流畅的线条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59885102/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com