unity 圆形障碍,避障算法,动态避障,静态避障,屎壳郎推屎回娘家

Unity3d圆形障碍避障算法,动态避障,静态避障

屎壳郎推屎回娘家
废话不多上图
unity 圆形障碍,避障算法,动态避障,静态避障,屎壳郎推屎回娘家_第1张图片
unity 圆形障碍,避障算法,动态避障,静态避障,屎壳郎推屎回娘家_第2张图片

1:根据,屎和娘家的位置做计算,不管屎在哪里,获取朝向娘家,屎后面一定距离的位置

//获取位置
    Vector3 GetTraget(Vector3 start, Vector3 end) //end 家
    {
        Vector3 normal = (end - start).normalized;
        float percent = -4; //距离屎保留一点距离
        return normal * (percent) + start;
    }

2:屎壳郎需要跑到屎后面,推屎回娘家,需要进行避障算法

//避障算法
    private List<Vector3> pathPoints = new List<Vector3>();
    private void FindPath(Vector3 palyerPos, Vector3 targetPos, Vector3 obstaclePos, float aroundRadius)
    {
        pathPoints.Add(palyerPos);
        Vector3 pathDir = targetPos - palyerPos;
        Vector3 pointDir = obstaclePos - palyerPos;
        float crossValue = Vector3.Cross(pathDir, pointDir).y;
        float angleDelta = 45;
        if (crossValue < 0)
        {
            angleDelta = -45;
        }
        Vector3 obstacleToPlayer = (palyerPos - obstaclePos).normalized;
        Vector3 obstacleToTarget = (targetPos - obstaclePos).normalized;
        float threshold = Vector3.Dot(obstacleToPlayer, obstacleToTarget);
        bool caculateFinished = false;
        int i = 1;
        do
        {   
            Quaternion randRotate = Quaternion.Euler(0, angleDelta * i, 0);
            Vector3 extendDir = (randRotate * obstacleToPlayer).normalized;
            Vector3 tempPos;
            if (Vector3.Dot(extendDir, obstacleToPlayer) <= threshold)
            {
                caculateFinished = true;
                tempPos = targetPos;
            }
            else
            {
                tempPos = obstaclePos + extendDir * aroundRadius;
            }
            pathPoints.Add(tempPos);
            ++i;
        } while (!caculateFinished);

        pathPoints.Add(targetPos);
    }

3:在推屎过程中出现不可抗拒因素,即时使用Update计算获取新的推屎路线,

哈哈啊哈~~~~~

你可能感兴趣的:(unity3d,避障算法,动态避障,unity,游戏引擎,c#,启发式算法,逻辑回归,游戏程序,关卡设计)