一、实现物体的抛物线运动

1.使用translate的方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Cylinder1 : MonoBehaviour
{public float v_x;public float v_y;private float g;// Start is called before the first frame updatevoid Start(){v_x = 5;v_y = 0;g = 9.8f;}// Update is called once per framevoid Update(){v_y = g*Time.fixedDeltaTime;transform.Translate(Vector3.right* v_x * Time.fixedDeltaTime, Space.World);transform.Translate(Vector3.down * v_y * Time.fixedDeltaTime, Space.World);}}

2.使用新建Vector3的方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Cylinder2 : MonoBehaviour
{public int v_x;private float g;// Start is called before the first frame updatevoid Start(){v_x = 5;g = 9.8f;}// Update is called once per framevoid Update(){float x = this.transform.position.x + v_x*Time.deltaTime;float y = this.transform.position.y - g*Time.deltaTime*Time.deltaTime/2;this.transform.position = new Vector3(x, y, 0);}}

3.直接修改position的方法

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Cylinder3 : MonoBehaviour
{public int v_x;public int v_y;private float g;// Start is called before the first frame updatevoid Start(){v_x = 5;v_y = 0;g = 9.8f;}// Update is called once per framevoid Update(){this.transform.position += Vector3.right*v_x;this.transform.position += Vector3.down*(v_y + g*Time.fixedDeltaTime);}
}

二、实现太阳系

  创建如下结构并设置好各行星的大小和距离

  将行星图片拖到对应的行星上,在Main Camera中设置背景为黑色,初始状态如下

  代码如下

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Rotate : MonoBehaviour {public Transform mercury;public Transform venus;public Transform earth;public Transform mars;public Transform jupiter;public Transform saturn;public Transform uranus;public Transform neptune;public Transform moon;public Transform earthclone;// Use this for initializationvoid Start () {mercury = this.transform.Find("Mercury");venus = this.transform.Find("Venus");earth = this.transform.Find("Earth");mars = this.transform.Find("Mars");jupiter = this.transform.Find("Jupiter");saturn = this.transform.Find("Saturn");uranus = this.transform.Find("Uranus");neptune = this.transform.Find("Neptune");earthclone = this.transform.Find("EarthClone");moon = earthclone.Find("Moon");}// Update is called once per framevoid Update () {mercury.RotateAround(this.transform.position, new Vector3(3, 15, 0), 47 * Time.deltaTime);mercury.Rotate(Vector3.up * Time.deltaTime * 300);venus.RotateAround(this.transform.position, new Vector3(2,10, 0), 35 * Time.deltaTime);venus.Rotate(Vector3.up * Time.deltaTime * 280);earth.RotateAround(this.transform.position, new Vector3(1, 10, 0), 30 * Time.deltaTime);earth.Rotate(Vector3.up * Time.deltaTime * 250);mars.RotateAround(this.transform.position, new Vector3(2, 15, 0), 24 * Time.deltaTime);mars.Rotate(Vector3.up * Time.deltaTime * 220);jupiter.RotateAround(this.transform.position, new Vector3(2, 10, 0), 13 * Time.deltaTime);jupiter.Rotate(Vector3.up * Time.deltaTime * 180);saturn.RotateAround(this.transform.position, new Vector3(1, 15, 0), 9 * Time.deltaTime);saturn.Rotate(Vector3.up * Time.deltaTime * 160);uranus.RotateAround(this.transform.position, new Vector3(2, 5, 0), 6 * Time.deltaTime);uranus.Rotate(Vector3.up * Time.deltaTime * 150);neptune.RotateAround(this.transform.position, new Vector3(3, 10, 0), 5 * Time.deltaTime);neptune.Rotate(Vector3.up * Time.deltaTime * 140);earthclone.RotateAround(this.transform.position, new Vector3(1, 10, 0), 30 * Time.deltaTime);moon.transform.RotateAround (earthclone.transform.position, new Vector3(1, 12, 0), 50 * Time.deltaTime);}
}

  选择组件-效果-拖尾渲染器,将时间设置为80,可以显示行星运行轨迹。
  最终效果如下:

  可以看出,月球绕地球公转,八大行星以不同速度、在不同法平面上绕太阳公转,并且八大行星都有自转。

视频效果

https://www.bilibili.com/video/BV1mG411J7q6/

unity实现抛物线及太阳系相关推荐

  1. 【用Unity实现抛物线向目标点发射炮弹功能】

    用Unity实现抛物线向目标点发射炮弹功能 游戏开发中经常会涉及到制作向特定的目标点投掷物体的功能,比如:塔防类.射击类.即时战斗类游戏-等等,首先需要明确的一点是,要打中目标点,发射的角度.发射点与 ...

  2. unity 模拟抛物线

    具体的步骤: 了解使用 水平方向的速度是:v1=v0×cosθ 竖直方向的速度是:v2=v0×sinθ-gt y=v0×t-(gt^2)/2 克隆线段,坐标信息,线段的长度,线段的间距. 检测碰撞的点 ...

  3. unity 模拟抛物线 1

    具体的步骤: 了解使用 水平方向的速度是:v1=v0×cosθ 竖直方向的速度是:v2=v0×sinθ-gt y=v0×t-(gt^2)/2 克隆线段,坐标信息,线段的长度,线段的间距. 检测碰撞的点 ...

  4. Unity中抛物线的实现

    什么是抛物线?   以数学知识来定义的话,抛物线是在平面内到定点与定直线的距离相等的点的轨迹叫做抛物线.定点就是抛物线的焦点,定直线就是抛物线的准线.从物理上来说的话,抛物线就是将一个物体抛出去以后, ...

  5. unity 显示太阳_太阳系究竟有多大?来看看天文学家是怎么解答的

    太阳系的界限或边界既超出了八个公认的行星,也超出了矮行星. 可以将太阳系定义为由引力约束的系统,其中包括太阳和直接或间接围绕太阳运行的物体.在直接绕太阳运行的物体中,最大的八个是行星,其余的是小行星, ...

  6. Unity中绘制抛物线

    效果如下: 之所以加个2,是因为我以前写过一个抛物线的文章,之前的文章请看这: Unity绘制抛物线代码 上一篇文章只是简单地绘制了一个抛物线,但是无法随意移动或者旋转,最近因为做个项目可能会用到这个 ...

  7. 简易太阳系及牧师与魔鬼

    3D游戏作业3 1.使用Unity实现完整的太阳系 要求:行星围绕太阳的转速必须不同,且不在一个法平面上. 过程:首先寻找太阳系各星球的贴图,并将其加载到项目的assets中.[行星贴图网址](Sol ...

  8. unity抛物线_发射弓箭轨迹的实现

    无论是愤怒的小鸟,还是弓箭发射功能,亦或者模拟炮弹受重力影响等抛物线轨迹,都可以使用本文的方法,模拟绝对真实. 和往常一样,先说原理.就是抛物运动,在垂直方向上做加速度运动,在水平方向上,做匀速运动. ...

  9. 【Unity】 结合DoTween制作抛物线效果

    [Unity] 结合DoTween制作抛物线效果 概要 public partial class EMath {public static Vector3 Parabola(Vector3 start ...

最新文章

  1. Redis面试连环问:集群、复制以及与其他NOSQL数据库的区别?
  2. iptables 常用规则使用实例
  3. requests模拟登陆 验证码
  4. 回滚master代码_Git之master主干代码回滚
  5. vba fso读utf 文本_利用FSO对象操作文件
  6. HDU1403(后缀数组--最长公共子串)
  7. 数据结构之图定义及相关概念
  8. OSSchedLock()--上锁函数
  9. jde 动态添加筛选条件的注意事项
  10. 3.SPSS Modeler数据基本分析笔记
  11. figma 导入导出 fig 文件
  12. 算法篇 干货!!!字母重排 打卡第七天
  13. Excel多条件计数——COUNTIFS【获奖情况统计】
  14. 从提示框:适用于Windows的iPad接口仿真,Easy Access iPhone手电筒和Kindle收藏管理...
  15. high sierra php,macOS High Sierra 上测试 Apache 和 PHP 站点
  16. 纯干货:docker可视化管理界面
  17. tm项目和fp项目_TM软件项目介绍
  18. Java中的不可变集合介绍
  19. 织梦Dede如何删除管理员admin
  20. pycharm中 Make available to all projects的含义

热门文章

  1. 智能红外线耳温枪方案开发
  2. springboot项目部署到阿里云
  3. 推荐几个数据分析宝藏公众号
  4. 高中信息技术python知识点,高中python语言常用语句
  5. 一个借鉴现代OS的MMU的排序算法
  6. FPGA基于VGA显示字符及图片
  7. 无线设备的破解和安全(破解篇)
  8. Word+Excel+PPT 2016三合一
  9. [STK] matlabSTK 安装
  10. pycharm怎么安装numpy库