Пример #1
0
 private void Awake()
 {
     alertState   = new alertState(this);
     attackState  = new attackState(this);
     patrolState  = new patrolState(this);
     chaseState   = new chaseState(this);
     navMeshAgent = GetComponent <NavMeshAgent>();
 }
Пример #2
0
    private chaseState()
    {
        if (instance != null)
        {
            return;
        }

        instance = this;
    }
Пример #3
0
    private chaseState()
    {
        if (_instance != null)
        {
            return; //Simply return if there is already an instance of attack
        }

        _instance = this; //set instance to this instance if there isn't already an instance
    }
Пример #4
0
    private void FixedUpdate()
    {
        Vector3 chaseDirection;

        if (enemyState == chaseState.wander)
        {
            chaseDirection = Wander();
            if ((player.transform.position - transform.position).magnitude < controller.detectionRadius)
            {
                enemyState = chaseState.chase;
            }
        }
        else if (enemyState == chaseState.chase)
        {
            chaseDirection = Seek(player.transform.position);
        }
        else
        {
            chaseDirection = Vector3.zero;
            drakeAnimation.SetBool("CanFollow", false);
        }

        // always move along the camera forward as it is the direction that it being aimed at
        Vector3 desiredMove = chaseDirection;

        // get a normal for the surface that is being touched to move along it
        RaycastHit hitInfo;

        Physics.SphereCast(transform.position, thisController.radius, Vector3.down, out hitInfo,
                           thisController.height / 2f, Physics.AllLayers, QueryTriggerInteraction.Ignore);
        desiredMove = Vector3.ProjectOnPlane(desiredMove, hitInfo.normal).normalized;

        moveDir.x = desiredMove.x * speed;
        moveDir.z = desiredMove.z * speed;

        if (thisController.isGrounded)
        {
            moveDir.y = -m_StickToGroundForce;
        }

        else
        {
            moveDir += Physics.gravity * m_GravityMultiplier * Time.fixedDeltaTime;
        }

        Vector3 toMove = moveDir * Time.fixedDeltaTime;

        Vector3 toMovenoY = new Vector3(toMove.x, 0, toMove.z);

        RaycastHit stopMovementHit;

        if (Physics.Raycast(new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z), toMovenoY, out stopMovementHit, 3))
        {
            if (enemyState == chaseState.chase)
            {
                enemyState = chaseState.howl;
            }
            else
            {
                futurePosition = new Vector3(Random.Range(0, 50), 0, Random.Range(0, 50));
            }
            toMove.x = 0;
            toMove.z = 0;
            Debug.Log(stopMovementHit.collider.tag);
        }

        thisController.Move(toMove);

        if (toMovenoY != Vector3.zero)
        {
            transform.forward = toMovenoY.normalized;
        }
    }