예제 #1
0
    // Seek using Steering mode.
    private void Seek(EnemyStateController controller, Vector3 targetpoint)
    {
        // Check for target dist from arrival radius
        Vector3 direction = targetpoint - controller.transform.position;
        // Vector3 direction = controller.nav_agent.steeringTarget - controller.transform.position;
        float distance = (direction).magnitude;

        if (distance < controller.enemy_stats.arrival_radius)
        {
            controller.current_vel   = Vector3.zero;
            controller.current_accel = Vector3.zero;

            return;
        }

        //Set accel
        controller.current_accel += direction.normalized * (controller.enemy_stats.maximum_acceleration) * Time.deltaTime;
        //cap accel
        if (controller.current_accel.magnitude > controller.enemy_stats.maximum_acceleration)
        {
            controller.current_accel.Normalize();
            controller.current_accel *= controller.enemy_stats.maximum_acceleration;
        }
        controller.current_vel += (controller.current_accel * Time.deltaTime);
        //cap vel
        if (controller.current_vel.magnitude > controller.enemy_stats.maximum_velocity)
        {
            controller.current_vel.Normalize();
            controller.current_vel *= controller.enemy_stats.maximum_velocity;
        }

        Vector3 newpos = controller.transform.position + (controller.current_vel * Time.deltaTime);

        controller.transform.position = newpos;
    }
예제 #2
0
 private void DoActions(EnemyStateController controller)
 {
     for (int i = 0; i < actions.Length; i++)
     {
         actions[i].Act(controller);
     }
 }
예제 #3
0
    private EnemyState CheckTransitions(EnemyStateController enemy)
    {
        // Find player.
        PlayerController player = (PlayerController)enemy.GetData <PlayerController>(StateData.Player);        //GameObject.FindGameObjectWithTag(Tags.Player).GetRequiredComponent<PlayerController>();

        for (int transitionIndex = 0; transitionIndex < m_Transitions.Length; transitionIndex++)
        {
            EnemyState nextState;

            if (m_Transitions[transitionIndex].CheckTransition(enemy, player))
            {
                nextState = m_Transitions[transitionIndex].GetTrueState;
            }
            else
            {
                nextState = m_Transitions[transitionIndex].GetFalseState;
            }

            if (nextState != null)
            {
                return(nextState);
            }
        }

        return(null);
    }
 public override void StateEnter()
 {
     detectCollider  = enemy.transform.Find("DetectCollider").GetComponent <Collider2D>();
     stateController = enemy.GetComponent <EnemyStateController>();
     //  Debug.Log("Looking for the enemy");
     lastTurn = stateController.timePatrolling;
 }
예제 #5
0
    private void SetupAI()
    {
        //get enemy state controller
        stateController = GetComponent <EnemyStateController>();

        //SetFlyHeightFromGround(flyHeight);
        aiActive = true;
        stateController.SetupStateController(this);
        rb.constraints = RigidbodyConstraints.FreezeRotation;

        //so darkling know where to return
        this.startTransform = new SaveTransform(this.transform);

        //assign type for darkling
        switch (darklingType)
        {
        case DarklingType.Idle:
            stateController.currentState = darklingIdleStartState;
            break;

        case DarklingType.Wander:
            stateController.currentState = darklingWanderStartState;
            break;

        //if not assign, leave it there
        default:
            break;
        }
    }
 // Initialization function for a state
 public void InitState(EnemyStateController controller)
 {
     for (int i = 0; i < actions.Length; i++)
     {
         actions[i].Init(controller);
     }
 }
    public override bool Decide(EnemyStateController controller)
    {
        DarklingAirEnemy darkling = (DarklingAirEnemy)controller.enemy;

        bool isTargetInZone = detectTarget(darkling);

        return(isTargetInZone);
    }
예제 #8
0
 void Start()
 {
     audioSource     = GetComponent <AudioSource>();
     stateController = transform.parent.GetComponent <EnemyStateController>();
     detectCollider  = GetComponent <Collider2D>();
     enemyCollider   = transform.parent.GetComponent <Collider2D>();
     Physics2D.IgnoreCollision(detectCollider, enemyCollider, true);
 }
 public override void StateEnter()
 {
     stateController = enemy.GetComponent <EnemyStateController>();
     bullet          = stateController.bullet;
     player          = stateController.detectedPlayer;
     lastAttack      = stateController.reactionTime;
     Debug.Log("Got you, ya son of a bitch!");
 }
예제 #10
0
    public override bool Decide(EnemyStateController controller)
    {
        SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy;

        bool targetDetected = Scan(skeleton);

        return(targetDetected);
    }
예제 #11
0
    public override void Act(EnemyStateController controller)
    {
        //simple cast
        SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy;

        //move
        Attack(skeleton);
    }
예제 #12
0
 private void DoActions(EnemyStateController controller)
 {
     // Loop through all actions associated with this state.
     for (int i = 0; i < actions.Length; i++)
     {
         // Do actions.
         actions[i].Act(controller);
     }
 }
예제 #13
0
    private void moveToStartPosition(EnemyStateController controller)
    {
        Vector3 targetLocation = controller.StartLocation;
        Vector3 newPosition    = controller.transform.position;
        Vector3 dir            = (targetLocation - newPosition).normalized;

        controller.transform.position = newPosition + dir * controller.Stats.MoveSpeed * Time.fixedDeltaTime;
        controller.transform.up       = dir;
    }
예제 #14
0
    /*
     * called by EnemyStateController, when transition to new state
     */
    public void OnExitState(EnemyStateController controller)
    {
        if (exitAction == null)
        {
            return;
        }

        exitAction.Act(controller);
    }
예제 #15
0
    private bool Scan(EnemyStateController controller)
    {
        // Vector3 tempScanPos = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), Random.Range(-1f, 1f));

        controller.agent.isStopped = true;

        // controller.transform.Translate(controller.transform.position + tempScanPos * controller.enemyStats.moveSpeed * Time.deltaTime);

        return(controller.CheckIfTimeElapsed(controller.enemyStats.searchDuration));
    }
예제 #16
0
    private void MoveTowardsPlayer(EnemyStateController controller)
    {
        Vector3 newPosition = controller.transform.position;
        Vector3 dir         = (controller.HeroTransform.position - newPosition).normalized;

        newPosition = newPosition + (dir * controller.Stats.MoveSpeed * Time.fixedDeltaTime);

        controller.transform.position = newPosition;
        controller.transform.up       = dir;
    }
예제 #17
0
    // Start is called before the first frame update
    void Start()
    {
        gettingSucked = false;
        Vector3 suckInfo = lookup.ContainsKey(enemyType) ? lookup[enemyType] : lookup["default"];

        suckRate   = suckInfo.x;
        suckLeft   = suckInfo.y;
        suckDamage = suckInfo.z;
        state      = gameObject.GetComponent <EnemyStateController>();
    }
예제 #18
0
    private void Patrol(EnemyStateController controller)
    {
        // controller.enemyAnim.SetTrigger("Walk");
        controller.agent.destination = controller.wayPointsList[controller.nextWayPoint].position;
        controller.agent.isStopped   = false;

        if (controller.agent.remainingDistance <= controller.agent.stoppingDistance && !controller.agent.pathPending)
        {
            controller.nextWayPoint = (controller.nextWayPoint + 1) % controller.wayPointsList.Count;
        }
    }
예제 #19
0
    private bool closeToLocation(EnemyStateController controller)
    {
        Vector3 myPosition = controller.transform.position;
        Vector3 distance   = controller.StartLocation - myPosition;

        if (distance.magnitude <= .5f)
        {
            return(true);
        }
        return(false);
    }
예제 #20
0
    public override bool Decide(EnemyStateController controller)
    {
        DarklingAirEnemy darkling = (DarklingAirEnemy)controller.enemy;


        if (darkling.isCloseEnoughToTarget(darkling.startTransform.position, 1))
        {
            return(true);
        }
        return(false);
    }
예제 #21
0
    public override bool Decide(EnemyStateController controller)
    {
        SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy;

        if (skeleton.isCloseEnoughToTarget(skeleton.startTransform.position, 1))
        {
            return(true);
        }

        return(false);
    }
예제 #22
0
    public void UpdateState(EnemyStateController enemy, EnemyStateController.StateCallback stateCallback)
    {
        UpdateStateLogic(enemy);

        // Check whether the state can transition to the next state.
        EnemyState nextState = CheckTransitions(enemy);

        if ((stateCallback != null) && (nextState != null))
        {
            stateCallback(nextState);
        }
    }
예제 #23
0
    private void Patrol(EnemyStateController controller)
    {
        controller.NavAgent.Resume();

        if (controller.NavAgent.path.reachedDestination)
        {
            controller.NavAgent.waypointIndex = (controller.NavAgent.waypointIndex + 1) % controller.NavAgent.waypoints.waypoints.Count;
            controller.NavAgent.NextWaypoint();
        }

        controller.SetWaypointLocation();
    }
예제 #24
0
    private void Suck(EnemyStateController controller)
    {
        bool playerLooking = controller.IsSeen();

        if (playerLooking)
        {
            Vector3 newPos = controller.HeroTransform.position;
            Vector3 dir    = controller.transform.position - newPos;

            controller.Hero.GetComponent <Rigidbody2D>().AddForce(dir.normalized * 375f, ForceMode2D.Force);
        }
    }
예제 #25
0
    protected override void UpdateStateLogic(EnemyStateController enemy)
    {
        PlayerController player = (PlayerController)enemy.GetData <PlayerController>(StateData.Player);

        // Move towards the next player position.
        enemy.GetNavMeshAgent.destination = player.gameObject.transform.position;
        enemy.GetNavMeshAgent.isStopped   = false;

        if (enemy.GetEnemyController.GetAnimator.IsAnimating == false)
        {
            enemy.GetEnemyController.GetAnimator.WalkForward();
        }
    }
예제 #26
0
    public override bool Decide(EnemyStateController controller)
    {
        DarklingAirEnemy darkling = (DarklingAirEnemy)controller.enemy;

        bool attackAgain = false;

        if (darkling.target != null && darkling.hasDoneAttacking)
        {
            attackAgain = true;
        }

        return(attackAgain);
    }
예제 #27
0
    public override void Act(EnemyStateController controller)
    {
        SkeletonEnemy skeleton = (SkeletonEnemy)controller.enemy;

        //simple check
        if (skeleton.patrolPositions.Length == 0)
        {
            return;
        }

        //move
        Patrol(skeleton);
    }
예제 #28
0
    public override void Act(EnemyStateController controller)
    {
        // Debug.Log("CHASE STATE");
        // Chase the player
        Vector2 chaseVector = Vector2.MoveTowards(
            controller.transform.position,
            controller.enemyMovementController.chaseTarget.position,
            Time.deltaTime * 5.0f);

        controller.transform.position = new Vector3(
            chaseVector.x,
            controller.transform.position.y,
            controller.transform.position.z);
    }
예제 #29
0
    private GameObject IsEnemyNearPlayer(EnemyStateController enemy)
    {
        // Get a list of colliders within the given radius of the enemy.
        Collider[] colliderList = Physics.OverlapSphere(enemy.GetEnemyController.transform.position, m_DistanceFromPlayer, Layers.GetLayerMask(Layers.Player));

        // In theory, the player should be the only thing on the player layer, so if the list is greater than 0, the player is within that radius.
        if (colliderList.Length > 0)
        {
            return(colliderList[0].gameObject);
        }
        else
        {
            return(null);
        }
    }
예제 #30
0
    public bool CheckTransition(EnemyStateController enemy, PlayerController player)
    {
        // For this transition to return true, all the decisions in the list must return true (&& relationship).
        for (int decisionIndex = 0; decisionIndex < m_Decisions.Length; decisionIndex++)
        {
            if (m_Decisions[decisionIndex].Decide(enemy, player) == false)
            {
                // Decision failed, transition can not be transitioned.
                return(false);
            }
        }

        // All the decisions were successful! Transition is a-go!
        return(true);
    }