Csharp/C#教程:Unity 5在圆形或椭圆形路径(轨道)中移动行星分享


Unity 5在圆形或椭圆形路径(轨道)中移动行星

我有:

void Update () { transform.RotateAround(transform.parent.position, new Vector3(0, 1, 0), orbitSpeed * Time.deltaTime); } 

这给了我一个非常基本的圆形轨道。

我需要做些什么来获得变化的椭圆轨道(每个恒星随机生成行星,所以我也想给它们随机轨道路径)?

你不能使用RotateAround。 你必须自己动手

尝试使用:

https://answers.unity3d.com/questions/133373/moving-object-in-a-ellipse-motion.html

 x, y: center of the ellipse a, b: semimajor and semiminor axes 

代码:

  var a : int; var b : int; var x: int; var y : int; var alpha : int; var X : int; var Y : int; function Update () { alpha += 10; X = x + (a * Mathf.Cos(alpha*.005)); Y= y + (b * Mathf.Sin(alpha*.005)); this.gameObject.transform.position = Vector3(X,0,Y); } 

编辑:

如果你想让它绕另一个物体运行,请使用:

上述就是C#学习教程:Unity 5在圆形或椭圆形路径(轨道)中移动行星分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

  this.gameObject.transform.position = anotherObject.transform.position + Vector3(X,0,Y); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1020011.html

(0)
上一篇 2022年1月4日
下一篇 2022年1月4日

精彩推荐