Exemplo n.º 1
0
        public bool FindPath(Vec3 from, Vec3 to, MovementFlag flags, ref List <Vec3> path, float merge_distance = -1, bool as_close_as_possible = false, bool include_from = false, float random_coeff = 0, bool bounce = false, float shift_nodes_distance = 0, bool smoothen = true)
        {
            using (m_Navmesh.AcquireReadDataLock())
            {
                List <path_pos> tmp_path = new List <path_pos>();

                if (from.IsEmpty || to.IsEmpty)
                {
                    return(false);
                }

                Cell start = null;
                Cell end   = null;

                bool start_on_nav_mesh = m_Navmesh.GetCellContaining(from, out start, flags, false, as_close_as_possible, -1, false, 2, null);
                bool end_on_nav_mesh   = m_Navmesh.GetCellContaining(to, out end, flags, false, as_close_as_possible, -1, false, 2, null);

                if (bounce)
                {
                    Vec3 bounce_dir = start.AABB.GetBounceDir2D(from);
                    Vec3 new_from   = from + bounce_dir * 10;
                    m_Navmesh.GetCellContaining(new_from, out start, flags, false, as_close_as_possible, -1, false, 2, null);

                    if (!Algorihms.FindPath <Cell>(start, ref end, new_from, to, flags, ref tmp_path, random_coeff, true))
                    {
                        return(false);
                    }

                    tmp_path.Insert(0, new path_pos(start.AABB.Align(from), start));
                }
                else
                {
                    if (!Algorihms.FindPath <Cell>(start, ref end, from, to, flags, ref tmp_path, random_coeff, true))
                    {
                        return(false);
                    }
                }

                if (smoothen && random_coeff == 0)
                {
                    SmoothenPath(ref tmp_path, flags, bounce ? 1 : 0);
                }

                if (DistToKeepFromEdge > 0 && random_coeff == 0)
                {
                    KeepAwayFromEdges(ref tmp_path, flags);
                }

                path = tmp_path.Select(x => x.pos).ToList();

                PostProcessPath(ref path, merge_distance, shift_nodes_distance);

                if (!include_from && start_on_nav_mesh)
                {
                    path.RemoveAt(0);
                }

                return(true);
            }
        }
Exemplo n.º 2
0
        public bool FindRoughPath(Vec3 from, Vec3 to, ref List <Vec3> path)
        {
            if (from.IsZero() || to.IsZero())
            {
                return(false);
            }

            List <path_pos> tmp_path = new List <path_pos>();

            bool start_on_nav_mesh = GetCellAt(from, out ExploreCell start);
            bool end_on_nav_mesh   = GetCellAt(to, out ExploreCell end);

            using (new ReadLock(DataLock))
                Algorihms.FindPath(start, from, new Algorihms.DestinationPathFindStrategy <ExploreCell>(to, end), MovementFlag.None, ref tmp_path, use_cell_centers: true);

            path = tmp_path.Select(x => x.pos).ToList();
            return(true);
        }