コード例 #1
0
    //public PlayerAgent(LayerMask enemyHitLayerMask, LayerMask floorHitLayerMask)
    //{
    //    this.enemyHitLayerMask = enemyHitLayerMask;
    //    this.floorHitLayerMask = floorHitLayerMask;
    //}


    #region Updates

    private void controllerUpdate()
    {
        verticleSpeed   = Mathf.Lerp(verticleSpeed, Input.GetAxis("Vertical"), 1);
        horizontalSpeed = Mathf.Lerp(horizontalSpeed, Input.GetAxis("Horizontal"), 1f);

        // Setting Character Aiming.
        if (Input.GetMouseButton(1) && !m_movingAgent.isEquipingWeapon())
        {
            m_movingAgent.aimWeapon();
        }
        else
        {
            m_movingAgent.stopAiming();
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            m_movingAgent.togglepSecondaryWeapon();
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            m_movingAgent.togglePrimaryWeapon();
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            m_movingAgent.toggleHide();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            m_movingAgent.dodgeAttack(getDirectionRelativeToCamera(new Vector3(verticleSpeed, 0, -horizontalSpeed)));
        }

        if (Input.GetKey(KeyCode.LeftShift))
        {
            speedModifyVale = Mathf.Lerp(speedModifyVale, 2, 0.1f);
            m_movingAgent.moveCharacter(getDirectionRelativeToCamera(new Vector3(verticleSpeed * speedModifyVale, 0, -horizontalSpeed * speedModifyVale)));
        }
        else
        {
            speedModifyVale = Mathf.Lerp(speedModifyVale, 1f, 0.1f);
            m_movingAgent.moveCharacter(getDirectionRelativeToCamera((new Vector3(verticleSpeed, 0, -horizontalSpeed)).normalized * speedModifyVale));
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            m_movingAgent.reloadWeapon();
        }


        UpdateShooting();

        UpdateTargetPoint();
    }
コード例 #2
0
    private void controllerUpdate()
    {
        if (!m_movingAgent.isEquiped())
        {
            switch (selectedWeaponType)
            {
            case Weapon.WEAPONTYPE.primary:
                m_movingAgent.togglePrimaryWeapon();
                break;

            case Weapon.WEAPONTYPE.secondary:
                m_movingAgent.togglepSecondaryWeapon();
                break;
            }
        }
        else
        {
            if (!m_movingAgent.isEquipingWeapon())
            {
                m_movingAgent.aimWeapon();
            }
            else
            {
                m_movingAgent.stopAiming();
            }
        }

        if (moveCounter > 0.2f)
        {
            moveDirection   = Random.insideUnitSphere;
            moveDirection.y = 0;
            moveCounter     = 0;
        }

        Vector3 targetPostion = enemy.transform.position;

        targetPostion.y = 1.5f;
        m_movingAgent.setTargetPoint(targetPostion);

        if (isInScreenLimit() && enableFire)
        {
            //if (shootingCounter > 1)
            //{
            //    targetPostion = player.transform.position;
            //    targetPostion = new Vector3(targetPostion.x, 1.2f + targetPostion.y, targetPostion.z);
            //    m_movingAgent.setTargetPoint(targetPostion);
            //    m_movingAgent.weaponFireForAI();
            //    shootingCounter = -Random.value * 3;
            //}

            //shootingCounter += Time.deltaTime * 2;

            if (!triggerPulled)
            {
                if (shootingCounter > 0.5f)
                {
                    m_movingAgent.pullTrigger();
                    triggerPulled   = true;
                    shootingCounter = 0;
                }
            }
            else
            {
                if (shootingCounter > 0.5f)
                {
                    m_movingAgent.releaseTrigger();
                    triggerPulled   = false;
                    shootingCounter = 0;
                    tempFloat       = Random.value * 10 + 1;
                }
            }
        }
        shootingCounter += Time.deltaTime;


        moveCounter += Time.deltaTime;

        // m_movingAgent.moveCharacter(moveDirection.normalized);
    }
コード例 #3
0
    protected void updateSelfAgentFromInput()
    {
        #region get control input
        float inputHorizontal = SimpleInput.GetAxis("Horizontal");
        float inputVertical   = SimpleInput.GetAxis("Vertical");

        float aimInputHorizontal = SimpleInput.GetAxis("HorizontalAim");
        float aimInputVertical   = SimpleInput.GetAxis("VerticalAim");

        Vector3 aimDirection = getDirectionRelativeToCamera(new Vector3(aimInputVertical, 0, -aimInputHorizontal));

        bool runPressed    = SimpleInput.GetButton("Run");
        bool crouchPressed = SimpleInput.GetButtonDown("Crouch");
        bool dodge         = SimpleInput.GetButtonDown("Dodge");
        bool rifle         = SimpleInput.GetButtonDown("Rifle");
        bool pistol        = SimpleInput.GetButtonDown("Pistol");
        #endregion

        #region control agent from input

        #region movment control

        if (rifle)
        {
            m_selfAgent.togglePrimaryWeapon();
        }

        if (pistol)
        {
            m_selfAgent.togglepSecondaryWeapon();
        }

        if (crouchPressed)
        {
            m_selfAgent.toggleHide();
            m_crouched = !m_crouched;
        }

        if (dodge)
        {
            m_selfAgent.dodgeAttack(getDirectionRelativeToCamera((new Vector3(inputVertical, 0, -inputHorizontal).normalized) * 1.5f));
        }

        if (runPressed)
        {
            if (m_selfAgent.isCrouched())
            {
                m_selfAgent.toggleHide();
            }

            m_selfAgent.moveCharacter(getDirectionRelativeToCamera((new Vector3(inputVertical, 0, -inputHorizontal).normalized) * 1.5f));
        }
        else
        {
            if (m_crouched && !m_selfAgent.isCrouched())
            {
                m_selfAgent.toggleHide();
            }
            m_selfAgent.moveCharacter(getDirectionRelativeToCamera(new Vector3(inputVertical, 0, -inputHorizontal).normalized));
        }


        #endregion

        #region aiming and fire control
        if (aimDirection.normalized.magnitude > 0)
        {
            m_selfAgent.aimWeapon();
            m_targetFinder.updateTargetFinder(aimDirection, this.transform.position);
            m_selfAgent.setTargetPoint(m_targetFinder.getCalculatedTargetPosition());

            if (m_targetFinder.canFireAtTargetAgent())
            {
                m_selfAgent.pullTrigger();
            }
            else
            {
                m_selfAgent.releaseTrigger();
            }
        }
        else
        {
            m_selfAgent.stopAiming();
            m_selfAgent.releaseTrigger();
            m_targetFinder.disableTargetIndicator();
        }
        #endregion

        #endregion
    }