Example #1
0
    public override BehaviourStatus OnBehave(BehaviourState state)
    {
        BehaviourContext enemyContext = (BehaviourContext)state;

        if (!enemyContext.enemyInRange(0.5f))
        {
            if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("attack"))
            {
                enemyContext.enemyAnimation.Play("walk");
            }
            return(BehaviourStatus.FAILURE);
        }

        if (GameObject.FindGameObjectWithTag("Player") != null)
        {
            playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
        }
        else
        {
            return(BehaviourStatus.SUCCESS);
        }

        enemyContext.enemyPhysics.enemyRotation(playerPosition);
        if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("idle") ||
            enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("walk"))
        {
            enemyContext.enemyAnimation.Play("attack");
        }
        enemyContext.enemyPhysics.enemyMovement(playerPosition, angle);

        return(BehaviourStatus.RUNNING);
    }
    public override BehaviourStatus OnBehave(BehaviourState state)
    {
        BehaviourContext enemyContext = (BehaviourContext)state;

        if (enemyContext.enemyInSight())
        {
            playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
        }

        if ((!enemyContext.enemyInRange(0.5f) && !enemyContext.enemyTooClose()))
        {
            enemyContext.enemyWeaponController.isFiring = false;
            return(BehaviourStatus.FAILURE);
        }

        if ((!enemyContext.enemyTooClose() && enemyContext.enemyInSight()))
        {
            enemyContext.enemyWeaponController.isFiring = false;
            return(BehaviourStatus.SUCCESS);
        }

        /////////////////////////////////////////////////////////////
        if (closestNode == null)
        {
            closestNode = PathFinder.getRetreatNode(enemyContext.pathNodes, enemyContext.enemyPhysics.transform, playerPosition);
        }

        if (PathFinder.atDestination(enemyContext.enemy.transform, closestNode.transform.position))
        {
            closestNode = PathFinder.getRetreatNeighbor(closestNode, enemyContext.enemy.transform, playerPosition);
            if (closestNode == null)
            {
                closestNode = PathFinder.getRetreatNode(enemyContext.pathNodes, enemyContext.enemyPhysics.transform, playerPosition);
            }
        }

        enemyContext.enemyPhysics.enemyRotation(playerPosition);
        if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("idle") ||
            enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("attack"))
        {
            enemyContext.enemyAnimation.Play("walk");
        }
        enemyContext.enemyPhysics.enemyMovement(closestNode.transform.position, angle);

        if (!enemyContext.enemyWeaponController.isFiring)
        {
            enemyContext.enemyWeaponController.isFiring = true;
        }
        ////////////////////////////////////////////////////////////////

        return(BehaviourStatus.RUNNING);
    }
Example #3
0
    //Leaf node that checks whether or not the target is not seen or heard so it can patrol.

    public override BehaviourStatus OnBehave(BehaviourState state)
    {
        BehaviourContext enemyContext = (BehaviourContext)state;

        if (!enemyContext.enemyInSight() && !enemyContext.enemyInRange(0.5f) && !enemyContext.playerHeard)
        {
            if (enemyContext.enemySight.enableDebug)
            {
                Debug.Log("Player Not Found");
            }

            return(BehaviourStatus.SUCCESS);
        }

        return(BehaviourStatus.FAILURE);
    }
Example #4
0
    //Leaf Node that checks whether or not it is directly close to the player for a melee attack.

    public override BehaviourStatus OnBehave(BehaviourState state)
    {
        BehaviourContext enemyContext = (BehaviourContext)state;

        if (enemyContext.enemyInRange(0.3f))
        {
            if (enemyContext.enemySight.enableDebug)
            {
                Debug.Log("Player Near");
            }

            enemyContext.startNode = null;
            return(BehaviourStatus.SUCCESS);
        }

        return(BehaviourStatus.FAILURE);
    }
Example #5
0
    public override BehaviourStatus OnBehave(BehaviourState state)
    {
        BehaviourContext enemyContext = (BehaviourContext)state;

        if (enemyContext.enemySight.getPlayerSeen() || enemyContext.enemyInRange(0.5f) || enemyContext.playerHeard)
        {
            return(BehaviourStatus.FAILURE);
        }


        if (patrolPath.Count == 0)
        {
            patrolPath = PathFinder.getPath(enemyContext.startNode, enemyContext.endNode);
        }

        if (patrolPath.Count > 0)
        {
            currentNode = (NodeController)patrolPath [pathCounter];
            modPositionOffset();

            if (PathFinder.atDestination(enemyContext.enemy.transform, currPos))
            {
                enemyContext.enemyAnimation.Play("idle");
                pathCounter++;
                currentNode = (NodeController)patrolPath [pathCounter];
                offsetMod   = false;
                modPositionOffset();
                if (currentNode.transform.position == enemyContext.endNode.transform.position)
                {
                    enemyContext.startNode = enemyContext.endNode;
                    enemyContext.startInfo = currentNode;
                    return(BehaviourStatus.SUCCESS);
                }
            }

            enemyContext.enemyPhysics.enemyRotation(currPos);
            if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("idle"))
            {
                enemyContext.enemyAnimation.Play("walk");
            }
            enemyContext.enemyPhysics.enemyMovement(currPos, angle);
        }

        return(BehaviourStatus.RUNNING);
    }
    //Leaf node responsible for getting the start node closest to the enemy and a random end node
    //responsible for the enemy patrolling.

    public override BehaviourStatus OnBehave(BehaviourState state)
    {
        BehaviourContext enemyContext = (BehaviourContext)state;

        if (enemyContext.enemyInSight() || enemyContext.enemyInRange(0.5f))
        {
            return(BehaviourStatus.FAILURE);
        }

        if (enemyContext.startNode == null)
        {
            enemyContext.startNode = PathFinder.getInitialNode(enemyContext.pathNodes,
                                                               enemyContext.enemyPhysics.transform.position);
            enemyContext.startInfo = enemyContext.startNode.GetComponent <NodeController> ();
        }
        enemyContext.endNode = PathFinder.getEndNode(enemyContext.pathNodes, enemyContext.startNode);
        return(BehaviourStatus.SUCCESS);
    }
Example #7
0
    public override BehaviourStatus OnBehave(BehaviourState state)
    {
        BehaviourContext enemyContext = (BehaviourContext)state;


        if (!enemyContext.enemyInRange(0.5f) || !enemyContext.enemyInSight() || enemyContext.enemyTooClose())
        {
            if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("attack"))
            {
                enemyContext.enemyAnimation.Play("idle");
            }
            enemyContext.enemyWeaponController.isFiring = false;
            return(BehaviourStatus.FAILURE);
        }

        if (GameObject.FindGameObjectWithTag("Player") != null)
        {
            playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
        }
        else
        {
            enemyContext.enemyWeaponController.isFiring = false;
            return(BehaviourStatus.SUCCESS);
        }

        enemyContext.enemyPhysics.enemyRotation(playerPosition);
        if (enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("idle") ||
            enemyContext.enemyAnimation.GetCurrentAnimatorStateInfo(0).IsName("walk"))
        {
            enemyContext.enemyAnimation.Play("attack");
        }

        if (!enemyContext.enemyWeaponController.isFiring)
        {
            enemyContext.enemyWeaponController.isFiring = true;
        }

        return(BehaviourStatus.RUNNING);
    }