Exemple #1
0
 public void Setup_For_Search(Pathing_Point target)
 {
     if (target != null)
     {
         H = Vector3.Distance(m_Position.position, target.m_Position.position);
     }
     else
     {
         H = float.PositiveInfinity;
     }
     m_Parent = null;
     m_Open   = NodeState.Untested;
 }
Exemple #2
0
    public bool Search(Pathing_Point curr, Pathing_Point target)
    {
        curr.m_Open = Pathing_Point.NodeState.Closed;
        List <Pathing_Point> next_nodes = GetAdjacentWalkableNodes(curr);

        next_nodes.Sort((node1, node2) => node1.Get_F().CompareTo(node2.Get_F()));
        foreach (Pathing_Point node in next_nodes)
        {
            if (node == target)
            {
                return(true);
            }
            else
            if (Search(node, target)) // Note: Recurses back into Search(Node)
            {
                return(true);
            }
        }
        return(false);
    }
    private void Leave_State()
    {
        switch (m_State)
        {
        // code transitions out of current state
        case Security_State.Patrol:
        {
            m_Path   = null;
            m_target = null;
            break;
        }

        case Security_State.Catch:
        {
            m_Target_Item = null;
            break;
        }

        case Security_State.Chase:
        {
            m_Alert_Object.SetActive(false);
            break;
        }

        case Security_State.Attack:
        {
            m_Alert_Object.SetActive(false);
            m_PunchTimer   = null;
            B_InUse        = false;
            B_Pressed      = false;
            B_Released     = true;
            curr_attacking = false;
            break;
        }

        default:
        {
            break;
        }
        }
    }
Exemple #4
0
    public Path CompilePath(Pathing_Point start, Pathing_Point end)
    {
        Path path    = new Path();
        bool success = Search(start, end);

        if (success)
        {
            Pathing_Point node = end;
            while (node.m_Parent != null)
            {
                path.Append(node);
                node = node.m_Parent;
            }
            path.Append(node);
            path.Reverse();
        }
        else if (start == end)
        {
            path.Append(start);
        }
        return(path);
    }
Exemple #5
0
    public Path Find_Path(Vector3 start, Vector3 end)
    {
        Path ret = new Path();
        // Get the closest node to the start position
        Pathing_Point first_node = Get_Nearest_Node(start);
        // Get the closest node to the end position
        Pathing_Point end_node = Get_Nearest_Node(end);

        // reset pathing points
        foreach (Pathing_Point node in m_Nodes)
        {
            node.Setup_For_Search(end_node);
        }
        if (first_node != null && end_node != null)
        {
            ret = CompilePath(first_node, end_node);
            return(ret);
        }
        else
        {
            return(null);
        }
    }
Exemple #6
0
    public Pathing_Point Get_Nearest_Node(Vector3 start_pos)
    {
        Pathing_Point ret      = null;
        float         distance = float.PositiveInfinity;

        foreach (Pathing_Point node in m_Nodes)
        {
            Turn_Node_Collision_On(node);
            RaycastHit hit;
            if (
                (Physics.Raycast(start_pos, node.m_Position.position - start_pos, out hit)) &&
                (hit.transform.gameObject == node.m_Position.gameObject)
                )
            {
                if (Vector3.Distance(start_pos, node.m_Position.position) < distance)
                {
                    distance = Vector3.Distance(start_pos, node.m_Position.position);
                    ret      = node;
                }
            }
            Turn_Node_Collision_Off(node);
        }
        return(ret);
    }
 public void Append(Pathing_Point point)
 {
     path.Add(point);
     num_points += 1;
 }
Exemple #8
0
 private void Turn_Node_Collision_On(Pathing_Point node)
 {
     node.gameObject.GetComponent <BoxCollider>().enabled = true;
 }