繁体   English   中英

Unity3D如何使用半径使对象开始以圆弧或圆移动?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM