• 大小: 179KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: 其他
  • 标签: Unity3d  模拟碰撞  

资源简介

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 < QiTaRen.Count; i++)
        //{
        //    OtherPos = QiTaRen[i].transform.position;
        //    if (Vector3.Distance(ThisPos OtherPos) < SafeDisatance)
        //    {
        //        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) < SafeDisatance)
            {
                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 < NeedToThink.Count; 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


评论

共有 条评论