美文网首页
2018-11-12 unity 在球上生成弧线作为两点连接线

2018-11-12 unity 在球上生成弧线作为两点连接线

作者: 流光念岁月 | 来源:发表于2018-11-12 11:15 被阅读0次

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SphereRadin : MonoBehaviour {
List<Vector3> posList = new List<Vector3>();
public float journeyTime = 3.0f;
// The time at which the animation started.
private float startTime;
private float runningTime, percentage,radin;
private Vector3 startPos;
private Vector3 endPos;
public LineRenderer line;
private Vector3 centerPos;

void Awake()
{
    startTime = Time.time;
}
private void FixedUpdate()
{
    runningTime += Time.deltaTime;
    percentage = runningTime / journeyTime;
    radin = Mathf.Sin(Mathf.PI * percentage) + 1f;
    if (percentage > 1)
    {
        return;
    }
    Vector3 riseRelCenter = startPos - centerPos;
    Vector3 setRelCenter = endPos - centerPos;
    transform.position = Vector3.Slerp(riseRelCenter * radin, setRelCenter * radin, percentage);
    transform.position += centerPos;
    posList.Add(transform.position);
    line.positionCount = posList.Count;
    line.SetPositions(posList.ToArray());
}

}

相关文章

网友评论

      本文标题:2018-11-12 unity 在球上生成弧线作为两点连接线

      本文链接:https://www.haomeiwen.com/subject/drvqfqtx.html