【发布时间】:2019-06-24 13:51:10
【问题描述】:
我在两个给定点之间生成小球体。但是它总是以直线生成。球体是否可以开始生成从 A 点到 B 点的曲线?
我通过定义NumberOfSegments来定义两点之间应该生成多少个球体。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GeneratePoints : MonoBehaviour
{
public Transform PointA;
public Transform PointB;
public float NumberOfSegments = 3;
public float AlongThePath = .25f;
// Update is called once per frame
void Start()
{
StartCoroutine(StartSpheringOut());
}
IEnumerator StartSpheringOut()
{
NumberOfSegments += 1;// since we are skipping 1st placement since its the same as starting point we increase the number by 1
AlongThePath = 1 / (NumberOfSegments);//% along the path
for (int i = 1; i < NumberOfSegments; i++)
{
yield return new WaitForSeconds(0.05f);
Vector3 CreatPosition = PointA.position + (PointB.position - PointA.position) * (AlongThePath * i);
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.position = CreatPosition;
sphere.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f);
}
}
}
【问题讨论】:
-
@derHugo 是的,我认为没有贝塞尔曲线我无法生成曲线。如果说我想做没有贝塞尔曲线,那么假设 A 点和 B 点之间的距离是 2 米,所以我必须在它周围生成 5-10 个点,所以它看起来像一条曲线。
-
所以你的意思是你创建一个半圆,中心位于 A 和 B 的中间?
-
@derHugo 是的