Materials used:
create scene
write script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cytaster : MonoBehaviour
{
[SerializeField]
private float rotate_speed; //自转速度
[SerializeField]
private Transform revolution_center; //公转中心
[SerializeField]
private float revolution_speed; //公转速度
void FixedUpdate() {
transform.Rotate(Vector3.forward*rotate_speed*Time.deltaTime);
if(revolution_point!=null){
transform.RotateAround(revolution_point.position,Vector3.forward,revolution_speed*Time.deltaTime);
}
}
}
Transform.Rotate(Vector3 eulers,Space relativeTo=Space.Self/Space.World)
Applies a rotation that rotates eulerAngles.z degrees around the Z axis, eulerAngles.x degrees around the X axis, eulerAngles.y degrees around the Y axis (in that order)
Transform.RotateAround(Vector3 point,Vector3 axis,float angle)
Rotates the transformation by angle degrees around the axis passing through the point in world coordinates
parameter settings
For ordinary planets, the center of revolution is the sun
For a planetary system, if the planetary system is used as the reference system, the satellite revolves around the main star
And the main star has no revolution, only rotation
Consider the main star and its satellites as a whole to complete the revolution in the star system, and use an empty object to represent the planetary system composed of the main star and its satellites (Sub-System in the figure below)
Mount the script for the object (Sub-System) to control the revolution of the entire planetary system in the star system