Example #1
0
    /// <summary>
    /// Creates and records a structure which contains information generated by
    /// the ray cast between the FROM and TO points.
    /// </summary>
    /// <param name="_from_offset">Start location of the ray.</param>
    /// <param name="_to_offset">End location of the ray.</param>
    void ProcessLine(Vector3 _from_offset, Vector3 _to_offset)
    {
        RaycastPackage ray_pack = new RaycastPackage();

        ray_pack.from      = transform.position + _from_offset;
        ray_pack.to        = ray_pack.from + _to_offset;
        ray_pack.direction = (ray_pack.to - ray_pack.from).normalized;
        ray_pack.length    = Vector3.Distance(ray_pack.from, ray_pack.to);

        EnumerateCoverPoints(ray_pack);

        ray_packs.Add(ray_pack);
    }
Example #2
0
    /// <summary>
    /// Performs a RaycastAll based on the ray pack's configuration and records the details of any hits.
    /// </summary>
    /// <param name="_ray_pack">The raycast configuration.</param>
    void EnumerateCoverPoints(RaycastPackage _ray_pack)
    {
        var hits = Physics.RaycastAll(_ray_pack.from, _ray_pack.direction,
                                      _ray_pack.length, hit_layers);

        foreach (var hit in hits)
        {
            NavMeshHit nav_hit;

            if (NavMesh.SamplePosition(hit.point + hit.normal, out nav_hit,
                                       nav_search_radius, NavMesh.AllAreas))
            {
                CoverPoint cover_point = new CoverPoint(cover_point_settings);

                cover_point.position = hit.point + hit.normal;
                cover_point.normal   = hit.normal;

                cover_points.Add(cover_point);
            }
        }
    }