コード例 #1
0
ファイル: SquadMember.cs プロジェクト: r2d2m/AT-AI-Squad
    void MainLogic()
    {
        if (order_override > 0.0f)
        {
            order_override -= 1000.0f * Time.deltaTime;
        }

        if (inCombat > 0.0f)
        {
            inCombat -= 1000.0f * Time.deltaTime;
        }

        if (!takingCover && danger > 50.0f && order_override <= 0.0f)
        {
            TakeCover();
        }

        if (danger - lastDanger > 50.0f && order_override <= 0.0f)
        {
            RefreshCover();
        }

        if (danger > 0.0f && (danger - lastDanger) <= 0.0f)
        {
            danger -= 1000.0f * Time.deltaTime;
        }

        lastDanger = danger;

        if (m_target != null)
        {
            AimAngle(m_target, false);
            inCombat = 3000.0f;
        }

        /*else if (m_covertarget != null)
         * {
         *  AimAngle(m_covertarget);
         *  inCombat = 3000.0f;
         * }*/

        if (stacking)
        {
            if (Vector3.Distance(transform.position, m_agent.destination) <= 1.0f)
            {
                if (stackCounter < 200.0f)
                {
                    stackCounter += Time.deltaTime * 1000.0f;
                }
                if (stackCounter >= 200.0f)
                {
                    doneStacking = true;
                }
            }
        }

        else if (m_waypoint != null)
        {
            if (!takingCover)
            {
                m_covertarget = null;
                switch (pos)
                {
                //to the left
                case 1:
                    m_agent.destination = m_waypoint.position - m_waypoint.right * 0.75f;
                    break;

                //to the right
                case 2:
                    m_agent.destination = m_waypoint.position + m_waypoint.right * 0.75f;
                    break;

                //behind
                case 3:
                    m_agent.destination = m_waypoint.position - m_waypoint.forward * 1.0f;
                    break;

                //behind left
                case 4:
                    m_agent.destination = m_waypoint.position - m_waypoint.forward * 2.0f - m_waypoint.right * 1.0f;
                    break;

                //behind right
                case 5:
                    m_agent.destination = m_waypoint.position - m_waypoint.forward * 2.0f + m_waypoint.right * 1.0f;
                    break;

                default:
                    m_agent.destination = m_waypoint.position;
                    break;
                }
            }
            else
            {
                if (m_covertarget != null)
                {
                    m_target = m_covertarget;
                }
                if (peek != 0)
                {
                    if (m_target != null)
                    {
                        AimAngle(m_target, false);
                    }
                    m_agent.destination = m_cover.position + m_cover.right * peek * 2.0f;
                    peekDur            -= 1000.0f * Time.deltaTime;
                    if (peekDur <= 0.0f)
                    {
                        m_agent.destination = m_cover.position;

                        peek = 0;

                        //target wasn't seen
                        if (!m_monitor.FinishMonitor())
                        {
                            ExitCover();
                        }
                        else
                        {
                            peekCooldown = 1000.0f;
                        }
                    }
                }
                else if (crouchPeek)
                {
                    if (m_target != null)
                    {
                        AimAngle(m_target, false);
                        if (m_monitor.IsMonitoring())
                        {
                            m_monitor.UpdateMonitor(m_target);
                        }
                    }
                    crouchPeekDur -= 1000.0f * Time.deltaTime;
                    if (crouchPeekDur <= 0.0f)
                    {
                        crouchPeek = false;

                        if (!m_monitor.FinishMonitor())
                        {
                            ExitCover();
                        }
                        else
                        {
                            crouchPeekCooldown = 2500.0f;
                        }
                    }
                }
                else
                {
                    m_agent.destination = m_cover.position;
                    if (inCover > 0.0f && Vector3.Distance(transform.position, m_cover.position) < 4.0f)
                    {
                        CoverSpot checkSpot = m_cover.GetComponent <CoverSpot>();
                        if (checkSpot != null)
                        {
                            if (checkSpot.IsShootable())
                            {
                                if (m_covertarget != null || checkSpot.IsLow())
                                {
                                    inCover += 1000.0f * Time.deltaTime;
                                    CoverShoot();
                                }
                                //holding = true;
                            }
                        }
                        else
                        {
                            inCover = 0.0f;
                        }
                        inCover -= 1000.0f * Time.deltaTime;
                        if (inCover <= 0.0f)
                        {
                            ExitCover();

                            if (regroup)
                            {
                                regroup = false;
                                Regroup();
                            }
                        }
                    }
                }
            }
        }

        Walk(Vector3.Distance(transform.position, prevPos) * 50.0f);
        prevPos = transform.position;

        if (!hasOrder && m_target == null)
        {
            CornerCheck();
        }

        if (holding && !takingCover && !stacking)
        {
            m_agent.destination = transform.position;
        }

        hasOrder = false;
    }
コード例 #2
0
    public void TakeCover()
    {
        //find cover
        if (!takingCover)
        {
            //m_oldpoint = m_waypoint;

            //get nearest cover
            int layerMask = 1 << 9;

            Collider[] coverSpots = Physics.OverlapSphere(transform.position, 30.0f, layerMask, QueryTriggerInteraction.Collide);
            float      value      = 200000.0f;

            foreach (Collider spot in coverSpots)
            {
                CoverSpot thisSpot = spot.GetComponent <CoverSpot>();

                if (!thisSpot.InUse())
                {
                    UnityEngine.AI.NavMeshPath testPath = new UnityEngine.AI.NavMeshPath();
                    m_agent.CalculatePath(spot.transform.position, testPath);

                    float   tempDist   = 0.0f;
                    Vector3 prevCorner = testPath.corners[0];

                    for (int i = 1; i < testPath.corners.Length; i++)
                    {
                        Vector3 curCorner = testPath.corners[i];
                        float   thisDist  = Vector3.Distance(prevCorner, curCorner);
                        tempDist += thisDist;
                        if (Physics.Raycast(prevCorner, (curCorner - prevCorner), thisDist, (1 << 12)))
                        {
                            tempDist += 100.0f;
                        }
                        prevCorner = curCorner;
                    }

                    float newDanger = thisSpot.GetSquadDanger();

                    float shootable = 0.0f;
                    if (thisSpot.IsLow())
                    {
                        //shootable = 40.0f;
                    }

                    float closeTarget = 0.0f;
                    if (m_target != null)
                    {
                        //closeTarget = Vector3.Distance(spot.transform.position, m_target.position) * 15.0f;
                    }

                    float newValue = (tempDist * 15.0f) + newDanger - shootable + closeTarget;

                    if (newValue < value)
                    {
                        //Debug.Log(tempDist + " " + newDanger + " " + newValue);
                        m_cover = spot.transform;
                        value   = newValue;
                    }
                }
            }

            CoverSpot checkSpot = m_cover.GetComponent <CoverSpot>();
            if (checkSpot != null)
            {
                checkSpot.SetUse(true);
                checkSpot.SetOwner(transform);
                inCover     = 3000.0f;
                takingCover = true;
                holding     = false;
            }
        }
    }
コード例 #3
0
ファイル: SquadMember.cs プロジェクト: r2d2m/AT-AI-Squad
    void CoverShoot()
    {
        if (m_covertarget != null)
        {
            m_target = m_covertarget;
        }

        bool      isLeftCorner  = false;
        bool      isRightCorner = false;
        bool      isLow         = false;
        CoverSpot checkSpot     = m_cover.GetComponent <CoverSpot>();

        if (checkSpot != null)
        {
            isLeftCorner  = checkSpot.IsLeftCorner();
            isRightCorner = checkSpot.IsRightCorner();
            isLow         = checkSpot.IsLow();

            if (isLow)
            {
                if (crouchPeekCooldown > 0.0f)
                {
                    crouchPeekCooldown -= 1000.0f * Time.deltaTime;
                }
                if (!m_gun[gunOut].Reloading() && !crouchPeek && crouchPeekCooldown <= 0.0f)
                {
                    //uncrouch
                    Uncrouch();
                    crouchPeek    = true;
                    crouchPeekDur = 300.0f;
                    m_monitor.Monitor(m_target);
                }
                if (!crouchPeek)
                {
                    Crouch();
                }
            }
            else
            {
                AimAngle(m_target, false);

                if (peekCooldown > 0.0f)
                {
                    peekCooldown -= 1000.0f * Time.deltaTime;
                }

                if (!m_gun[gunOut].Reloading() && peek == 0 && peekCooldown <= 0.0f)
                {
                    Debug.Log("peeking");
                    m_monitor.Monitor(m_covertarget);
                    peekDur = 400.0f;
                    if (isLeftCorner)
                    {
                        peek = -1;
                    }
                    else
                    {
                        peek = 1;
                    }
                }
            }
        }
    }