unity3d - 在 Unity 3D 版本 2019 中绕太阳旋转地球
问题描述
我在统一 3D 中创建了一个场景。它有3个球体,一个是太阳,第二个是地球,第三个是月亮。我让月亮成为地球的孩子。我的地球围绕太阳垂直旋转,月亮围绕地球旋转。我想要水平轴上的旋转。
革命的代码如下:
using UnityEngine;
using System.Collections;
public class revolve : MonoBehaviour {
public Transform target; // the object to rotate around
public int speed; // the speed of rotation
void Start()
{
if (target == null)
{
target = this.gameObject.transform;
Debug.Log ("RotateAround target not specified. Defaulting to parent GameObject");
}}
// Update is called once per frame
void Update ()
{
// RotateAround takes three arguments, first is the Vector to rotate around
// second is a vector that axis to rotate around
// third is the degrees to rotate, in this case the speed per second
transform.RotateAround(target.transform.position,target.transform.forward,speed * Time.deltaTime);
}}
建议在水平轴上进行哪些更改。
解决方案
更改最后一行
transform.RotateAround(target.transform.position,target.transform.forward,speed * Time.deltaTime);
至
transform.RotateAround(target.transform.position,target.transform.right,speed * Time.deltaTime);
推荐阅读
- javascript - 如何提高性能
- protractor - 如何为功能中的每个场景关闭和打开浏览器 - 量角器和 cucumberjs
- azure - 策略 rewrite-uri 在 Azure APIM 中附加上下文变量
- java - 如何通过纯 Java 类读取 OSGI 配置
- javascript - 如何正确地将 ES6 模块函数导出为库以在节点应用程序中使用?
- python - 如何使用 matplotlib/seaborn 获得亮度保持灰度的调色板
- angular - 如何在 ngx bootstrap datepicker 中更改消息“无效日期”而不在节点模块中
- css - Angular 2+,使用 ngClass 以缓慢的过渡速度从右到左浮动
- python - Python中的多色散点图图例
- python - 如何在 Python 中向网站发送多个 get 请求?