Пример #1
0
        Vector3 GetFixedPosition(Vector3 pos1, Vector3 direction1, Vector3 pos2, Vector3 direction2, float height)
        {
            Vector3 pos         = pos1;
            Vector3 newPosition = PEUtil.GetRandomPosition(pos1 + m_Data.Anchor, direction1, m_Data.firRadius, m_Data.sndRadius - 0.5f, -90.0f, 90.0f);

            if (PEUtil.CheckPositionNearCliff(newPosition))
            {
                pos         = pos2;
                newPosition = PEUtil.GetRandomPosition(pos2 + m_Data.Anchor, direction2, m_Data.firRadius, m_Data.sndRadius - 0.5f, -90.0f, 90.0f);
            }

            RaycastHit hitInfo;
            Ray        ray = new Ray(pos, Vector3.up);

            //Target in the hole
            if (Physics.Raycast(ray, out hitInfo, 128.0f, PEConfig.GroundedLayer))
            {
                ray = new Ray(newPosition, Vector3.up);
                if (Physics.Raycast(ray, out hitInfo, 128.0f, PEConfig.GroundedLayer))
                {
                    //hole in water
                    if (PEUtil.CheckPositionUnderWater(hitInfo.point - Vector3.up))
                    {
                        return(newPosition);
                    }
                    else
                    {
                        ray = new Ray(newPosition, Vector3.down);
                        if (Physics.Raycast(ray, out hitInfo, 128.0f, PEConfig.GroundedLayer))
                        {
                            return(hitInfo.point + Vector3.up);
                        }
                    }
                }
                else
                {
                    return(Vector3.zero);
                }
            }
            else
            {
                //Target not in the hole
                Ray rayStart = new Ray(newPosition + 128.0f * Vector3.up, -Vector3.up);
                if (Physics.Raycast(rayStart, out hitInfo, 256.0f, PEConfig.GroundedLayer))
                {
                    if (PEUtil.CheckPositionUnderWater(hitInfo.point))
                    {
                        return(newPosition);
                    }
                    else
                    {
                        return(hitInfo.point + Vector3.up);
                    }
                }
            }
            return(Vector3.zero);
        }