Exemplo n.º 1
0
    /// <summary>
    /// Roughly calculate time to go all the path with given speed
    /// </summary>
    /// <param name="path">Path to calculate</param>
    /// <param name="speed">Speed of the agent</param>
    /// <returns>Time in seconds</returns>
    public static float GetTimeToPass(this NavMeshPath path, float speed)
    {
        var   length = path.GetLength();
        float time   = length / speed;

        time += (path.corners.Length - 1) * .5f;         // slowdown on corners offset
        return(time);
    }
Exemplo n.º 2
0
    public override float GetCost()
    {
        var a    = m_Actor.IActor;
        var path = new NavMeshPath();

        a.NavMeshAgent.CalculatePath(a.Employee.Job.transform.position, path);

        var travelTime = path.GetLength();

        Debug.Log(travelTime);
        return(0);
    }
Exemplo n.º 3
0
    public override float GetCost()
    {
        var prereq_sum      = Prerequisites.Select(p => p.GetCost()).Sum();
        var opt_sum         = DecideFromOptions().GetCost();
        var inv_travel_time = 0f;
        var a = m_Actor.IActor;

        // No extra cost if for travelling to your own inventory
        if (TargetInventory != a.Inventory)
        {
            var path = new NavMeshPath();
            a.NavMeshAgent.CalculatePath(m_TargetInventory.transform.position, path);

            inv_travel_time = path.GetLength();
            Debug.Log(inv_travel_time);
        }

        return(prereq_sum + opt_sum + inv_travel_time);
    }
Exemplo n.º 4
0
    /// <summary>
    /// Get point on path
    /// </summary>
    /// <param name="path">Path to calculate</param>
    /// <param name="rate">Percent on path, from 0 to 1</param>
    public static Vector3 GetPointOnPath(this NavMeshPath path, float rate)
    {
        rate = Mathf.Clamp01(rate);
        var   length      = path.GetLength();
        float elapsedRate = 0;

        for (var i = 1; i < path.corners.Length; i++)
        {
            var from        = path.corners[i - 1];
            var to          = path.corners[i];
            var pieceLength = Vector3.Distance(from, to);
            var pieceRate   = pieceLength / length;
            elapsedRate += pieceRate;

            if (rate <= elapsedRate)
            {
                var rateOffset  = elapsedRate - rate;
                var rateOnPiece = 1 - rateOffset / pieceRate;
                return(Vector3.Lerp(from, to, rateOnPiece));
            }
        }

        return(path.corners[path.corners.Length - 1]);
    }