[英]Unity3D how to make an object start moving in an arc or circle using radius?
Unity3D,C#
我想知道如何使用半徑平滑移動對象,我希望對象從 transform.position 開始在一個圓圈中移動,就像這樣:我想要做的示例,並且只使用 C# 腳本,我可以想到正在使用如下變換。
timeCounter += Time.deltaTime * speed;
float x = Mathf.Cos(timeCounter) * width;
float z = Mathf.Sin(timeCounter) * height;
transform.position = new Vector3(x, 0, z);
我試過這個https://forum.unity.com/threads/how-to-make-an-object-move-in-a-circular-motion-at-constant-speed.526107/但它不是我想要,我的答案( https://youtu.be/V2A-0yOUNwc )使物體快速向右移動,它以中間位置為中心然后從右邊開始移動,我無法控制哪個角度它將開始。
嘗試Transform.RotateAround
:
using UnityEngine;
public class RotateAround : MonoBehaviour
{
public Vector3 rotatingPoint;
private Vector3 rotAxis = new Vector3(0,1,0);
void Start()
{
}
void Update()
{
transform.RotateAround(rotatingPoint, rotAxis, 1f);
}
}
檢查 文檔。 您設置旋轉點、旋轉軸和角度,就是這樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.