unity模拟太阳系(粒子系统版太阳)

本工程为模拟太阳系
环境为Unity2018.4.14

实现了太阳系八大行星绕太阳的公转和自传
和其他模拟太阳系的u3d模型不同的是,太阳用了粒子系统来实现,我使用了3个粒子系统特效外加一个红色球体来实现太阳。
为了美观和形象我还设置了各个行星的拖尾。

在这里插入图片描述
在这里插入图片描述

在层级(hierarchy)目录新建球体,排布好位置,将纹理移动到八大行星上,行星的设置就完成了。

新建一个空物体,挂上脚本rotateArround,点击物体,在检查器窗口设置好太阳和八大行星,运行脚本就可以实现行星的公转和自传。(脚本和纹理素材在末尾)


粒子特效主体是psSunSurface,也是太阳的主体,主要思路是形状设为球体,发射速度变为0,再设置粒子起始生命周期和粒子起始大小,再做些补充。(3个粒子特效具体设置见视频或文章末尾)

新建一个材质sunSurface,材质shader设置为 Legacy Shaders/Particles/Additive(soft)
sunSurface材质的Particle Texture图片选择smoke
然后粒子特效psSunSurface渲染器的Texture选择sunSurface材质


PsCorona,这个特效是给太阳表面增添一点红光,设置思路同上,具体参数不同。渲染器材质一样,也可新建一个材质做调整。


PsLoop,这个特效是太阳外围的风暴状红光。设置思路同上,具体参数不同。

新建一个材质sunLoop,材质shader设置为 Legacy Shaders/Particles/Additive
sunSurface材质的Particle Texture图片选择sun_texture1
然后粒子特效psSunSurface渲染器的Texture选择sunLoop材质


给太阳增添具体的轮廓,需要在psSunSurface粒子系统中心处加一个红色球体 (RGB:(209, 35, 0))
缩放x:20,y:20,z:20


想把背景调暗可设置灯光

设置灯光之前在层级窗口新建一个点光源,放在太阳位置,范围调大,我设置为300

设置灯光:把Directional Light之旋转的x轴调低到比-20小


rotateArround脚本

using System.Collections;
using System.Collections.Generic;

using UnityEngine;

public class moverotate : MonoBehaviour
{
	public GameObject Sun;//太阳
	public GameObject Mercury;//水星
	public GameObject Venus;//金星
	public GameObject Earth;//地球
	public GameObject Mars;//火星
	public GameObject Jupiters;//木星
	public GameObject Saturn;//土星
	public GameObject Uranus;//天王星
	public GameObject Neptune;//海王星
	
	public float Sun_RotationSpeed;
	public float Mercury_RotationSpeed;
	public float Venus_RotationSpeed;
	public float Earth_RotationSpeed;
	public float Mars_RotationSpeed;
	public float Jupiters_RotationSpeed;
	public float Saturn_RotationSpeed;
	public float Uranus_RotationSpeed;
	public float Neptune_RotationSpeed;
   //定义自转速度
	
	void Start () {
		
	}
	
	
	void Update () {
        Mercury.transform.RotateAround(Sun.transform.position, Sun.transform.up, 2.35f);
        Venus.transform.RotateAround(Sun.transform.position, Sun.transform.up, 1.75f);
        Earth.transform.RotateAround(Sun.transform.position, Sun.transform.up, 1.5f);
        Mars.transform.RotateAround(Sun.transform.position, Sun.transform.up, 1.2f);
        Jupiters.transform.RotateAround(Sun.transform.position, Sun.transform.up, 0.65f);
        Saturn.transform.RotateAround(Sun.transform.position, Sun.transform.up, 0.23f);
        Uranus.transform.RotateAround(Sun.transform.position, Sun.transform.up, 0.34f);
        Neptune.transform.RotateAround(Sun.transform.position, Sun.transform.up, 0.27f);
        //实现绕太阳自转
        Sun.transform.Rotate(Vector3.down * Sun_RotationSpeed, Space.World);
        Mercury.transform.Rotate(Vector3.down * Mercury_RotationSpeed, Space.World);
        Venus.transform.Rotate(Vector3.down * Venus_RotationSpeed, Space.World);
        Earth.transform.Rotate(Vector3.down * Earth_RotationSpeed, Space.World);
        Mars.transform.Rotate(Vector3.down * Mars_RotationSpeed, Space.World);
        Jupiters.transform.Rotate(Vector3.down * Jupiters_RotationSpeed, Space.World);
        Saturn.transform.Rotate(Vector3.down * Saturn_RotationSpeed, Space.World);
        Uranus.transform.Rotate(Vector3.down * Uranus_RotationSpeed, Space.World);
        Neptune.transform.Rotate(Vector3.down * Neptune_RotationSpeed, Space.World);
        //实现自转



    }
}


给行星设置拖尾

选择行星,在检查器界面添加组件
搜索trail
在这里插入图片描述

材料元素设置为Default-particle
时间设置为3

其余行星复制一遍拖尾渲染器就行
在这里插入图片描述

====================================================================
资源

粒子系统制作太阳视频教程
https://www.bilibili.com/video/BV1YT4y1E7DS/?spm_id_from=333.999.0.0&vd_source=1f2c95f726ceaa5c86643a5817ac8d44

行星纹理材质来源
教你如何用Three.js创造一个三维太阳系

前端开发博客
https://blog.csdn.net/lgno2/article/details/119431693?spm=1001.2014.3001.5506

====================================================================

粒子纹理素材
smoke
smoke
sun_texture 1
corona粒子纹理

粒子特效设置
psSunSurface

在这里插入图片描述

生命周期内颜色,在上面新设置两个标签条,透明的Alpha调整为255,实现生命周期边缘透明效果
在这里插入图片描述
生命周期RGB为(255,175,54)

PsCorona
在这里插入图片描述
生命周期内颜色
在这里插入图片描述

PsLoop

在这里插入图片描述
生命周期内颜色
在这里插入图片描述



额外的添头
月球绕地球旋转脚本 //直接挂载到月球上

using System.Collections;
using System.Collections.Generic;

using UnityEngine;

public class MoonRotate : MonoBehaviour
{
	
	//转动速度
	public float speed = 1;
	//转动的位置
	public float progress = 0;
	//中心点
	public Transform center;
	//半径
	public float radius;

	float dis(Transform center) //计算半径
	{
		float dis = (this.transform.position - center.position).magnitude;
		return dis;
	}
	

	void star()
	{
		radius = dis(center);
	}

	void Update() {
		
		progress += Time.deltaTime * speed;
		if (progress>=360)
		{
			progress -= 360;
		}
		float x1 = center.position.x + radius * Mathf.Cos(progress);
		float y1 = this.transform.position.y;
		float z1 = center.position.z + radius * Mathf.Sin(progress);
		this.transform.position = new Vector3(x1, y1, z1);
	}

	
}


  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
Unity是一款强大的游戏开发引擎,它提供了一系列的工具和功能可以帮助开发者实现太阳系运动的模拟。实现太阳系的运动模拟需要涉及到一些物理计算和渲染效果的应用。 首先,我们可以使用Unity的物理引擎来计算行星的运动轨迹。每个天体都可以被建模为一个刚体,并赋予初始位置、速度和质量等属性。通过使用万有引力定律,我们可以在每一帧中更新天体之间的相互作用力,然后计算得出新的位置和速度。以此方式,我们可以模拟行星绕太阳的运动以及其他行星之间的相互影响。 其次,我们可以设计逼真的天空盒和贴图来呈现太阳系的景象。通过在Unity中创建一个巨大的球体作为天空盒,并将太阳、行星、卫星等模型放置到正确的位置上,我们可以达到更加逼真的效果。此外,还可以使用Unity粒子系统模拟一些天体特有的效果,比如彗星的尾巴或者行星的大气层。 此外,Unity还提供了一套强大的渲染引擎,使我们可以在模拟中实现逼真的光照效果。通过配置灯光的类型、位置和强度等属性,我们可以模拟太阳光的照射效果,并让行星表面产生逼真的阴影效果。 最后,为了提高模拟的逼真度,我们还可以添加一些附加的特效,比如星云、流星雨、日食、月食等,以及一些声音效果来增强用户的体验。 总的来说,Unity是一个非常适合实现太阳系运动模拟的工具。通过利用其物理引擎、渲染引擎和特效功能,我们可以创建出一个真实且逼真的太阳系模拟,让用户更好地了解和探索太阳系的运动。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值