コード例 #1
0
        /// <summary>
        /// Performs a raycast on the navigation mesh to perform line of sight or similar checks
        /// </summary>
        /// <param name="start">Starting point</param>
        /// <param name="end">Ending point</param>
        /// <param name="querySettings">Advanced settings to be provided to the navigation mesh query</param>
        /// <returns>The found raycast hit if <see cref="NavigationRaycastResult.Hit"/> is true</returns>
        public NavigationRaycastResult Raycast(Vector3 start, Vector3 end, NavigationQuerySettings querySettings)
        {
            NavigationRaycastResult result = new NavigationRaycastResult {
                Hit = false
            };

            Navigation.RaycastQuery query;
            query.Source                = start;
            query.Target                = end;
            query.MaxPathPoints         = querySettings.MaxPathPoints;
            query.FindNearestPolyExtent = querySettings.FindNearestPolyExtent;
            Navigation.RaycastResult queryResult;
            Navigation.DoRaycastQuery(navmesh, query, new IntPtr(&queryResult));
            if (!queryResult.Hit)
            {
                return(result);
            }

            result.Hit      = true;
            result.Position = queryResult.Position;
            result.Normal   = queryResult.Normal;
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Performs a raycast on the navigation mesh to perform line of sight or similar checks
        /// </summary>
        /// <param name="start">Starting point</param>
        /// <param name="end">Ending point</param>
        /// <param name="querySettings">Advanced settings to be provided to the navigation mesh query</param>
        /// <returns>The found raycast hit if <see cref="NavigationRaycastResult.Hit"/> is true</returns>
        public unsafe NavigationRaycastResult Raycast(Vector3 start, Vector3 end, NavigationQuerySettings querySettings)
        {
            NavigationRaycastResult result = new NavigationRaycastResult { Hit = false };

            if (NavigationMeshInternal == IntPtr.Zero)
                return result;

            Navigation.RaycastQuery query;
            query.Source = start;
            query.Target = end;
            query.MaxPathPoints = querySettings.MaxPathPoints;
            query.FindNearestPolyExtent = querySettings.FindNearestPolyExtent;
            Navigation.RaycastResult queryResult;
            Navigation.DoRaycastQuery(NavigationMeshInternal, query, new IntPtr(&queryResult));
            if (!queryResult.Hit)
                return result;

            result.Hit = true;
            result.Position = queryResult.Position;
            result.Normal = queryResult.Normal;
            return result;
        }