Example #1
0
    /*---------------------------------------------------------------------------------*/
    // Detect Collisions with our personal collider -- for player stampede recognition //
    void OnTriggerEnter(Collider col)
    {
        //If Player enters hitbox trigger && conqueror-type skeleton -- transition to dieing
        if (col.tag == "Player" && blockState != blockingState.Dead && tag == "Skeleton")
        {
            Vector3 targetDir = col.gameObject.transform.position - transform.position;
            float   angle     = Vector3.Angle(targetDir, transform.forward);
            if (angle < 90)               //facing towards player
            {
                _animator.SetTrigger("dieBackwards");
            }
            else
            {
                _animator.SetTrigger("dieForwards");
            }

            //Over the top collision effect
            capCollider.isTrigger = false;       //Disables trigger collider enabling detection of ground
            rBody.isKinematic     = false;       //Disables kinematic control allowing physic based effects
            rBody.useGravity      = true;        //Enables gravity to manage bringing npc down to ground

            // rBody.AddExplosionForce (20.0f, playerRenderer.bounds.center, 3f,0.2f,ForceMode.Impulse); //Applies explosive force
            rBody.AddExplosionForce(20.0f, new Vector3(transform.position.x, playerRenderer.bounds.center.y, playerRenderer.bounds.center.z), 6f, 0.25f, ForceMode.Impulse); //Applies explosive force

            //Set to dead state
            blockState = blockingState.Dead;

            //Deactivates attack hitbox incase we were mid attack animation
            attackHitBox.gameObject.SetActive(false);
        }
    }
Example #2
0
 /*------------------------------------------*/
 // Detect Collision with our hitbox trigger //
 public void playerProximityEnter()
 {
     //If Player enters hitbox trigger -- transition to attack
     if (behaviour == hostileType.Block && blockState != blockingState.Dead)
     {
         blockState = blockingState.Attacking;
     }
 }
Example #3
0
 /*-----------------------*/
 // Detect Collision exit //
 public void playerProximityExit()
 {
     if (behaviour == hostileType.Block && blockState != blockingState.Dead)
     {
         _animator.ResetTrigger("proximityAttack");
         acquirePosition();
         blockState = blockingState.Moving;
     }
 }
Example #4
0
    /*--------------------------------------------------------------*/
    // Function to Pursue the Player and try to defend against them //
    public void BlockPlayer()
    {
        Vector3    targetRot;
        Quaternion newRot;
        Vector2    minBlockBoundary;
        Vector2    maxBlockBoundary;

        switch (blockState)
        {
        /*-------------------------------------*/
        // Idle State -- Default Initial state //
        case blockingState.Idle:

            //Grab first location to move too
            acquirePosition();
            blockState = blockingState.Moving;
            break;

        /*--------------------------------------------------*/
        // Moving state -- movement between block locations //
        case blockingState.Moving:
            _animator.SetBool("isWalking", true);
            //Get Target rotation to lerp towards
            targetRot             = currentBlockPos - transform.position;
            newRot                = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(targetRot), rotationSpeed * Time.deltaTime);
            transform.rotation    = newRot;
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

            //Begin movement towards blocking location
            transform.position = Vector3.MoveTowards(transform.position, currentBlockPos, movementSpeed * Time.deltaTime);
            if (transform.position == currentBlockPos)
            {
                blockingProgress = 0;
                blockState       = blockingState.Blocking;
                _animator.SetBool("isWalking", false);
            }
            break;

        /*---------------------------------------------------------------------------------------*/
        // Blocking state -- when stationary, rotate to face player and move on after a set time //
        case blockingState.Blocking:

            // Calculate the vector from player to position
            targetRot = player.position - transform.position;

            //Calculate the Quaternion for the rotiation
            newRot = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(targetRot), rotationSpeed * Time.deltaTime);

            //Apply rotation and 0 out axis apart from y-rotation
            transform.rotation    = newRot;
            transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);

            //Increment blocking timer
            if (blockingProgress < blockDuration)
            {
                blockingProgress += Time.deltaTime;
            }
            else
            {
                acquirePosition();
                blockState = blockingState.Moving;
            }

            //If player passes by them, immediately attempt to block a new position
            if (transform.position.z < player.transform.position.z - 0.2f)
            {
                acquirePosition();
                blockState = blockingState.Moving;
            }

            break;

        /*-----------------------------------------------------------------------*/
        // Attacking state -- When the Player gets too close, attempts to attack //
        case blockingState.Attacking:
            _animator.SetTrigger("proximityAttack");
            _animator.SetBool("isWalking", false);
            break;

        /*-----------------------------------------------------------------------------*/
        // Dead State -- When the player chrashes into it, destroys object after delay //
        case blockingState.Dead:
            destroyThis(5);             //Cleans up object after 5 seconds
            break;
        }
    }