Example #1
0
    /// <summary>
    /// This method is used to decide which tile the robot has to reach. All the potential tiles are the one that are free and near an unknown one
    /// </summary>
    /// <returns></returns>
    public IEnumerator ChoosingPointToReach()
    {
        while (!targetFound)
        {
            //RemovingWrongDetection();
            DetectingFrontierPoints();

            //Debug.Log(posToReach.Count);
            if (posToReach.Count != 0)
            {
                goals    = posToReach;
                tempGoal = rDM.PosToReach(goals);

                if (route != null)
                {
                    route.Clear();
                }

                route          = rPl.CheckVisibility(transform.position, tempGoal);
                rM.tempReached = false;

                if (route == null && noPath)
                {
                    numeric_robot_map[(int)FixingRound(tempGoal.x / squareSize), (int)FixingRound(tempGoal.z / squareSize)] = numUnknownCell;
                    goals    = posToReach;
                    tempGoal = rDM.PosToReach(goals);

                    if (route != null)
                    {
                        route.Clear();
                    }

                    route          = rPl.CheckVisibility(transform.position, tempGoal);
                    rM.tempReached = false;
                }

                //Debug.Log(route);
                if (route == null)
                {
                    rM.ApproachingPointToReach(tempGoal);
                }
                else
                {
                    rM.ApproachingPointToReach(route, 0);
                }
            }
            else
            {
                transform.Rotate(Vector3.up * Time.deltaTime * 20f);
            }

            yield return(new WaitForSeconds(timeForDecision));
        }
    }
    /// <summary>
    /// This method returns the lest cost for the robot agent to reach a certain point
    /// </summary>
    /// <param name="dest"></param>
    /// <returns></returns>
    private float CalculatingPathCost(Vector3 dest)
    {
        candidatePathCost = 0f;
        candidatePath     = rPL.CheckVisibility(transform.position, dest);
        if (candidatePath == null)
        {
            candidatePathCost = Mathf.Sqrt(((transform.position.x - dest.x) * (transform.position.x - dest.x)) + ((transform.position.z - dest.z) * (transform.position.z - dest.z)));
        }
        else
        {
            for (int i = 0; i < candidatePath.Count - 1; i++)
            {
                candidatePathCost += Mathf.Sqrt(((candidatePath[i].x - candidatePath[i + 1].x) * (candidatePath[i].x - candidatePath[i + 1].x)) + ((candidatePath[i].z - candidatePath[i + 1].z) * (candidatePath[i].z - candidatePath[i + 1].z)));
            }
        }

        return(candidatePathCost);
    }
Example #3
0
    /// <summary>
    /// This method instantiates one of the destination points of a trajectory line. The DP is chosen according to index value
    /// </summary>
    /// <param name="goals">The list of destination points of the trajectory line</param>
    /// <param name="index">The position, in the list, of the destination point to instantiate</param>
    public void ApproachingPointToReach(List <Vector3> goals, int index)
    {
        if (tempDestination)
        {
            Destroy(tempDestination);
            tempReached = false;
        }

        tempDestination = new GameObject();

        //Debug.Log("List: " + goals.Count + ", starting with " + index);

        List <Vector3> supplementaryPos = new List <Vector3>();
        float          distance         = Mathf.Sqrt((transform.position.x - goals[index].x) * (transform.position.x - goals[index].x) + (transform.position.z - goals[index].z) * (transform.position.z - goals[index].z));

        if (Physics.Linecast(transform.position, goals[index], layerMask) || distance > rangeRays)
        {
            supplementaryPos = rPL.CheckVisibility(transform.position, goals[index]);
            if (supplementaryPos != null)
            {
                for (int i = 0; i < supplementaryPos.Count - 1; i++)
                {
                    goals.Insert(index, supplementaryPos[i]);
                }
            }
        }

        tempDestination.transform.position = goals[index];
        tempDestination.AddComponent <BoxCollider>();
        tempDestination.GetComponent <BoxCollider>().size      = new Vector3(1f, 1f, 1f);
        tempDestination.GetComponent <BoxCollider>().isTrigger = true;
        tempDestination.AddComponent <RobotSpoofedDestPath>();
        tempDestination.GetComponent <RobotSpoofedDestPath>().robot = this.gameObject;
        tempDestination.GetComponent <RobotSpoofedDestPath>().index = index;
        tempDestination.GetComponent <RobotSpoofedDestPath>().path  = goals;
        tempDestination.tag   = "Opponent";
        tempDestination.layer = 13;
    }