> 文档中心 > 本科课程【虚拟现实引擎Unity3D】实验1 - ChaosBall(物理引擎应用)

本科课程【虚拟现实引擎Unity3D】实验1 - ChaosBall(物理引擎应用)


大家好,我是【1+1=王】, 热爱java的计算机(人工智能)渣硕研究生在读。
如果你也对java、人工智能等技术感兴趣,欢迎关注,抱团交流进大厂!!!
Good better best, never let it rest, until good is better, and better best.

近期会把自己本科阶段的一些课程设计、实验报告等分享出来,供大家参考,希望对大家有帮助。

博客更新至专栏【课程设计实验报告】:https://blog.csdn.net/weixin_43598687/category_11640051.html

一、 实验目的

  1. 掌握钢体的应用及相关控制方法、事件编程。

二、 实验内容

1. 实验任务

自己搭建一个类似台球桌面的场景,四个角设定为不同颜色,场景中有四个和角颜色对应的大球和若干个小的干扰球(颜色可相同或不同),场景中还有一个可以四处移动并转运的挡板,可以用其改变球的运动方向。游戏开始后,各种球以不同的速度和方向移动并和台球桌边、其它球及挡板相碰,在球碰撞到同颜色的角时停下不再移动。当四个大球都停在角上时,显示游戏结束提示和完成时间并可结束或重新开始游戏。可根据需要增加其他内容。

2. 程序设计

1) 数据输入
均为初始化方式输入

2) 数据存储(输入数据在内存中的存储)
Plane存储地面;
Cube1-4存储场景的四边框
Sphere1-4存储运动的小球
Cylinder1-4存储四个角的圆柱体
3) 数据处理
(1)
新建一个Plane(10x10)地面,四个Cube(1x1x10),四个Spyder(0.5x0.5x0.5),四个cylinde(1x1x1);
建立五个材质球分别赋给不同的对象;
调整不同物体至对应位置

(2)
给所有Cube,Spyder,cylinde添加刚体组件。
禁用cude的重力属性,再freeze冻结所有cude的x,y,z坐标,使它们在运动过程中保持静止。
新建一个Physic Material,初始化所有阻力系数都为0
本科课程【虚拟现实引擎Unity3D】实验1 - ChaosBall(物理引擎应用)
将新建的physic Material 拖动赋值给所有物体,使所有物体的运动阻力位0;

4) 数据输出
本科课程【虚拟现实引擎Unity3D】实验1 - ChaosBall(物理引擎应用)

三、 实验环境

  1. 操作系统:WINDOWS 10
  2. 开发工具:Unity3D
  3. 实验设备:PC

源代码

using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class Controller : MonoBehaviour { public Text text;    private int count = 0;    private bool isClick = false;    // Use this for initialization    void Start () { text.text = "white"; text.color = Color.white;}// Update is called once per framevoid Update () {  System.Threading.Thread.Sleep(2000); if (isClick == false) {     shunxuanzhuan(); } else {     nixuanzhuan(); } }    void shunxuanzhuan()    { count++; if(count !=0&&count%4 == 0) {     text.text = "white";     text.color = Color.white;     text.transform.position = new Vector2(text.transform.position.x, text.transform.position.y +50); } if (count % 4 == 1) {     text.text = "green";     text.color = Color.green;     text.transform.position = new Vector2(text.transform.position.x+50, text.transform.position.y); } if (count % 4 == 2) {     text.text = "yellow";     text.color = Color.yellow;     text.transform.position = new Vector2(text.transform.position.x, text.transform.position.y-50); } if (count % 4 == 3) {     text.text = "red";     text.color = Color.red;     text.transform.position = new Vector2(text.transform.position.x - 50, text.transform.position.y); }    }    void nixuanzhuan()    { count--; if (count != 0 && count % 4 == 0) {     text.text = "white";     text.color = Color.white;     text.transform.position = new Vector2(text.transform.position.x - 50, text.transform.position.y); } if (count % 4 == 1) {     text.text = "green";     text.color = Color.green;     text.transform.position = new Vector2(text.transform.position.x, text.transform.position.y-50); } if (count % 4 == 2) {     text.text = "yellow";     text.color = Color.yellow;     text.transform.position = new Vector2(text.transform.position.x + 50, text.transform.position.y); } if (count % 4 == 3) {     text.text = "red";     text.color = Color.red;     text.transform.position = new Vector2(text.transform.position.x, text.transform.position.y + 50); }    }    private void OnGUI()    { if(GUI.Button(new Rect(0, 0, 50, 30), "Button")) {     isClick = !isClick; }    }}using System.Collections;using System.Collections.Generic;using UnityEngine;public class sport : MonoBehaviour { // Use this for initializationvoid Start () { GetComponent().AddForce(400, 0, 333);}// Update is called once per framevoid Update () { }}

博客更新至专栏【课程设计实验报告】:https://blog.csdn.net/weixin_43598687/category_11640051.html

影搜视频