【问题标题】:Unity3D how to make an object start moving in an arc or circle using radius?Unity3D如何使对象开始使用半径在弧或圆中移动?
【发布时间】:2021-11-01 15:43:25
【问题描述】:

Unity3D,C#

我想知道如何使用半径平滑移动对象,我希望对象从transform.position开始以圆形移动,像这样:sample of what I want to do,并且只使用C#脚本,我能想到的of 正在使用如下变换。

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)使对象快速向右移动,它使用中间位置作为中心,然后从右侧开始移动,而且我无法控制它会从哪个角度开始。

【问题讨论】:

    标签: c# visual-studio unity3d


    【解决方案1】:

    试试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);   
        }
    }
    

    检查documentation。你设置旋转点,旋转轴和角度,就是这样。

    【讨论】:

      猜你喜欢
      • 2021-02-27
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 2017-12-06
      • 2016-08-25
      相关资源
      最近更新 更多