Unity3d Learning Notes (3)--making a simple solar system

Source: Internet
Author: User

This time to achieve a simple solar system, the sun itself with light source, the other planets around the sun's rotational speed is not the same (the farther the revolution slower), and not in a normal plane.

First, create 1 Suns and 9 planets in the scene, and then name them separately. The 9 planets are arranged in the following order: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune, Pluto. They are then extended to the X axis in order to make it easy to know that the rotation normals of the planets are (0,y,z), so make sure that the planets are not in a normal plane, just make sure y/z are not equal.

I wanted to distinguish the sun from the other planets, and I decided to give light to the sun (I said to have light). How to do it. Unity does not have spontaneous light components, if we try to add a point light source in the sun, then you will surely find strange phenomenon, the sun itself does not shine, but will illuminate others ...


So I used the Unity third party plug-in glow11,unity load Plug-in method:menu->assests->Import Package-> Custom package, note that the path cannot have Chinese. GLOW11: Add the GLOW11 component to the main camera, create a material material ball, select shader GLOW11 spontaneous light shader, mount the material ball onto the Sun object, adjust the material ball and point light color.



The next step is to write the script, the script is very simple, the main use of the Transform object Rotatearound method. The method accepts 3 parameters, the first of which is the rotation around the point, where the sun is positioned, the second is the normal vector of rotation, where the normal vector is in the (0,y,z) plane and the third is the speed of rotation. To facilitate the setting of the rotation center and speed, I set them to public variables.

public class Rotate:monobehaviour {public

    Transform origin;
	public float speed =;
	float ry, RZ;

	void Start () {
		ry = Random.range (1, 360);
		RZ = Random.range (1, 360);
	}
	
    void Update () {
		Vector3 axis = new Vector3 (0, Ry, RZ);
		This.transform.RotateAround (origin.position, axis, speed*time.deltatime);
	}

Random Y and Z let the planet try not to rotate in a normal plane. Mount the script on each planet and set the rotation Center (sun) and rotational speed.

To allow the orbits of the planets to manifest, you can add footprint components to each planet (Effects->trailer render):




Final Run Results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.