資源簡介
Unity3d非物理引擎模擬碰撞效果,做了開放修改,可以在u3d的編輯面板改屬性,屬性建議值在圖片中

代碼片段和文件信息
using?System.Collections;
using?System.Collections.Generic;
using?UnityEngine;
public?class?People?:?MonoBehaviour?{
????public?int?Name;
????public?float?SafeDisatance;
????public?float?DangerDistance;
????public?float?EachDisForce;
????public?float?XMax=10;
????public?float?XMin=-10;
????public?float?ZMax=10;
????public?float?ZMin=-10;
????public?int?ToleCount?=?0;
????Vector3?Zero?=?new?Vector3(000);
????Vector3?Fit?=?new?Vector3(0.5f00.5f);
????Vector3?speed=new?Vector3();
???//?public?List?QiTaRen?=?new?List();//1111111111111111111111111111
????public?List?QiTaRenNum?=?new?List();//222222222222222222222222222
????public?List?NeedToThink?=?new?List();
????//public?PeopleRoot?Root=PeopleRoot.GetInstance();
????void?ChooseNeedToThink()
????{
????????Vector3?ThisPos=this.gameobject.transform.position;
????????Vector3?OtherPos;
????????//#region?很大的性能開銷
????????//for?(int?i?=?0;?i?????????//{
????????//????OtherPos?=?QiTaRen[i].transform.position;
????????//????if?(Vector3.Distance(ThisPos?OtherPos)?????????//????{
????????//????????NeedToThink.Add(i);
????????//????}
????????//}
????????//#endregion
????????#region?鬼畜的開始
????????for?(int?i=0;i ????????{
????????????//?OtherPos?=?PeopleRoot.GetInstance().PeoplePile[QiTaRenNum[i]].gameobject.transform.position;
????????????OtherPos?=?PeopleRoot.GetInstance().PeoplePileSingleMode[QiTaRenNum[i]].gameobject.transform.position;
????????????if?(Vector3.Distance(ThisPos?OtherPos)?????????????{
????????????????NeedToThink.Add(i);
????????????}
????????}
????????#endregion
????}
????Vector3?CalculateSinglePower(Vector3?Other)
????{
????????Vector3?Force;
????????float?Power?=((SafeDisatance-DangerDistance)?-Vector3.Distance(this.gameobject.transform.position?Other))/?(SafeDisatance?-?DangerDistance)*EachDisForce;
????????Force.x?=?Other.x?-?this.gameobject.transform.localPosition.x;
????????if(Force.x>0)
????????{
????????????Force.x?=?0.1f*Power;
????????}
????????else
????????{
????????????Force.x?=?-0.1f*Power;
????????}
????????Force.y?=?0;
????????Force.z?=?Other.z?-?this.gameobject.transform.localPosition.z;
????????if?(Force.z?>?0)
????????{
????????????Force.z?=?0.1f*Power;
????????}
????????else
????????{
????????????Force.z?=?-0.1f*Power;
????????}
????????return?Force;
????}
????Vector3?CalculateNeed()
????{
????????Vector3?All=new?Vector3(000);
????????Vector3?Temp;
????????//#region?很大的性能開銷
????????//for?(int?i=0;i ????????//{
????????//??Temp=CalculateSinglePower(QiTaRen[NeedToThink[i]].gameobject.transform.position);
????????//????All.x?+=?Temp.x;
????????//????All.z?+=?Temp.z;
????????//}
????????//#endregion
????????#region?鬼畜的計算
????????for?(int?i?=?0;?i?????????{
????????????//??Temp?=?CalculateSinglePower(PeopleRoot.Ge
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????98167??2017-08-12?14:46??小球相撞\2017812-144557.jpg
?????文件?????111787??2017-08-12?14:46??小球相撞\2017812-144631.jpg
?????文件???????6519??2017-08-11?16:57??小球相撞\People.cs
?????文件???????2529??2017-08-11?16:57??小球相撞\PeopleRoot.cs
?????文件?????????46??2017-08-12?14:43??小球相撞\說明.txt
?????目錄??????????0??2017-08-12?14:46??小球相撞
-----------?---------??----------?-----??----
???????????????219048????????????????????6
- 上一篇:PID控速小車
- 下一篇:spring-cloud demo
評論
共有 條評論