using UnityEngine;
using System.Collections;
public class zhuan : MonoBehaviour
{
public Transform sun;
public float r; //半径
public float w; //角度
public float speed;
public float x;
public float y;
void Awake()
{
transform.position = new Vector3(10 * Random.value, 10 * Random.value, 0); //重置做圆周的开始位置
GameObject sun = GameObject.FindGameObjectWithTag("sun"); //取得圆点 我用一个sphere 表示
r = Vector3.Distance(transform.position, sun.transform.position); //两个物品间的距离
w = 0.3f; // ---角速度
speed = 1 * Random.value; // 这个应该所角速度了
}
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
//下面的概念有点模糊了
w += speed * Time.deltaTime; //
x = Mathf.Cos(w) * r;
y = Mathf.Sin(w) * r;
transform.position = new Vector3(x, y, transform.position.z);
}
}Unity物体绕圆运动-轨迹
最新推荐文章于 2026-04-10 11:52:55 发布
本文介绍如何使用Unity实现一个简单的星球环绕效果。通过设定角速度、星球间距离等参数,利用数学公式计算星球的位置坐标,使小星球围绕中心星球进行圆周运动。此示例适用于初学者学习Unity及游戏物理的基础知识。
该文章已生成可运行项目,
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印
本文章已经生成可运行项目
开发板推荐:天空星STM32F407VET6开发板
超高性价比 STM32主控 | 超高主频 | 一板兼容百芯 | 比赛神器 | 沉金彩色丝印
1万+

被折叠的 条评论
为什么被折叠?



