コード例 #1
0
    protected override void OnNPCSpawn()
    {
        //Banshee is by default Idlling, moves on agression or sight
        CurrentState = EAIState.ALIVE | EAIState.IDLE;

        m_HealthPoints = 100;
    }
コード例 #2
0
 private void Attack()
 {
     if (!CurrentState.HasFlag(EAIState.ATTACKING))
     {
         CurrentState = CurrentState | EAIState.ATTACKING;
     }
 }
コード例 #3
0
 private void NotAttacking()
 {
     if (CurrentState.HasFlag(EAIState.ATTACKING))
     {
         CurrentState -= EAIState.ATTACKING;
     }
 }
コード例 #4
0
        public static string    GetAIStateName(EAIState aiState)
        {
            switch (aiState)
            {
            case EAIState.IDLE:
                return("闲置");

            case EAIState.BORN:
                return("出生");

            case EAIState.PATROL:
                return("巡逻");

            case EAIState.FOLLOW:
                return("跟随");

            case EAIState.ESCAPE:
                return("逃跑");

            case EAIState.CHASE:
                return("追击");

            case EAIState.BACK:
                return("回家");

            case EAIState.FIGHT:
                return("攻击");

            case EAIState.DEAD:
                return("死亡");

            default:
                return("未知");
            }
        }
コード例 #5
0
 public static void InvokeChangeStateEvent(EventData eventData, EAIState state)
 {
     if (ChangeStateEvent != null)
     {
         ChangeStateEvent(eventData, state);
     }
 }
コード例 #6
0
ファイル: ActorAI.cs プロジェクト: mengtest/skilldemo
 public void ChangeAIState(EAIState pAIState)
 {
     if (AIState != pAIState)
     {
         AIState = pAIState;
         AIStateMachine.ChangeState(pAIState);
     }
 }
コード例 #7
0
 protected override void ChangeStateEventHandler(EventData eventData, EAIState state)
 {
     if (this.BehaviourObservesEvent(eventData) && state == _aiStateManagerBehaviour.GetAIState())
     {
         base.ChangeStateEventHandler(eventData, state);
         OnFollowStart();
     }
 }
コード例 #8
0
 protected override void ChangeStateEventHandler(EventData eventData, EAIState state)
 {
     if (this.BehaviourObservesEvent(eventData) && state == _stateBehaviour)
     {
         base.ChangeStateEventHandler(eventData, state);
         OnChase();
     }
 }
コード例 #9
0
ファイル: EMonster.cs プロジェクト: Tiaoyu/TServer
 public EMonster() : base()
 {
     AIState             = EAIState.PATROL;
     SightDistance       = 150;
     CanBeSeeDistance    = 150;
     AutoAttackDistance  = 5;
     LeaveCombatDistance = 10;
 }
コード例 #10
0
 public void MoveToState(EAIState pendingState)
 {
     if (_availiableStates [pendingState] != null)
     {
         _currentState.OnLeave();
         _currentState = _availiableStates [pendingState];
         _currentState.OnEnter();
     }
 }
コード例 #11
0
 private void PathfindChase()
 {
     //Switch to chase if player in range
     if (PlayerInRange(6f, true))
     {
         _pathAgent.pathfindingTarget = player;
         state = EAIState.chase;
         _behaviourText.text = "Chase";
     }
 }
コード例 #12
0
    void Update()
    {
        //for debug testing only
        if (Input.GetKeyDown(KeyCode.V))
        {
            CurrentState = CurrentState | EAIState.DYING;
        }

        if (!isLocalPlayer)
        {
            NPCDecision();
        }

        if (CurrentState != previousState)
        {
            ChangeAnimations();
        }
    }
コード例 #13
0
ファイル: AIBase.cs プロジェクト: Zenith26/CodeSamples
    void PatrolState()
    {
        if (Target == null)
        {
            return;                                         // only one line so just do like this, line below will be a false statement
        }
        navAgent.SetDestination(Target.transform.position); // using AI system to move the target

        //Deal Damage
        float _distance = 0;

        _distance = Vector3.Distance(gameObject.transform.position, Target.transform.position); // returns the distance from point A to B

        if (_distance < attackRange)                                                            // if the distance is lesser than the attackRange, initiate AttackState. P.S not using if check collider tag anymore
        {
            currentState = EAIState.Attack;
        }
    }
コード例 #14
0
    private void GroundPatrol(ref Vector2 input)
    {
        //Switch to flee if player in range
        if (PlayerInRange(6f, true))
        {
            state = EAIState.flee;
        }
        if (direction == 1 && (_controller.p_pCollisionInfo.right || _controller.p_pCollisionInfo.below))
        {
            direction = -1;
        }
        else if (direction == -1 && (_controller.p_pCollisionInfo.left || _controller.p_pCollisionInfo.below))
        {
            direction = 1;
        }

        input.x = direction;
    }
コード例 #15
0
    private void ChangeAnimations()
    {
        if (CurrentState.HasFlag(EAIState.ALIVE))
        {
            m_animator.animator.SetBool(IDliving, true);
        }
        if (CurrentState.HasFlag(EAIState.IDLE))
        {
            m_animator.animator.SetBool(IDmove, false);
            m_animator.animator.SetBool(IDattack, false);
            m_animator.animator.SetBool(IDdeath, false);
        }
        if (CurrentState.HasFlag(EAIState.MOVING))
        {
            m_animator.animator.SetBool(IDmove, true);
        }
        if (CurrentState.HasFlag(EAIState.ATTACKING))
        {
            m_animator.animator.SetBool(IDattack, true);
        }
        if (!CurrentState.HasFlag(EAIState.ATTACKING) && previousState.HasFlag(EAIState.ATTACKING))
        {
            m_animator.animator.SetBool(IDattack, false);
        }
        if (CurrentState.HasFlag(EAIState.DYING))
        {
            m_animator.animator.SetBool(IDliving, false);

            //now called via animation event
            //KillNPC();
        }
        if (CurrentState.HasFlag(EAIState.DEAD))
        {
            m_animator.animator.SetBool(IDdeath, true);
        }

        previousState = CurrentState;
    }
コード例 #16
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (Roll(5))
     {
         myRigidbody.AddTorque(0, Random.Range(-randomTorqueRange, randomTorqueRange), 0);
     }
     timeSinceLastDecision += .1f;
     if (timeSinceLastDecision >= decisionTime)
     {
         timeSinceLastDecision = 0;
         if (Vector3.Distance(transform.position, flankTargetSingleton.position) < followRange)
         {
             if (myState == EAIState.Following || Roll(70))
             {
                 myState = EAIState.Following;
             }
             else if (Roll(70))
             {
                 myState = EAIState.Wandering;
             }
             else
             {
                 myState = EAIState.Idle;
             }
         }
         else if (Roll(70))
         {
             myState = EAIState.Wandering;
         }
         else
         {
             myState = EAIState.Idle;
         }
     }
     DoState();
 }
コード例 #17
0
 public void BecomeIdle()
 {
     state = EAIState.Idle;
 }
コード例 #18
0
 private void Chase()
 { //Add this method into AiController
     _pathAgent.pathfindingTarget = player;
     state = EAIState.chase;
     _behaviourText.text = "Chase";
 }
コード例 #19
0
    private void Flee()
    {
        fFleeTimer += Time.deltaTime;
        if (fFleeTimer >= fleeTimer)
        {
            fFleeTimer = 0;
            if (_pathAgent.GetNodesFromCompletion() > 2)
            {
                return;
            }
            if (!PlayerInRange(7f, true) && _controller.p_pCollisionInfo.below)
            {
                state = EAIState.groundpatrol;
                _behaviourText.text = "Ground Patrol";
                _pathAgent.CancelPathing(); return;
            }

            float radius      = 8f; //Max range for random node
            float innerRadius = 3f; //Min range for random node

            List <CPathfinding.pathNode> nodes       = _pathScript.GetGroundAndLadders();
            List <CPathfinding.pathNode> nodesInArea = new List <CPathfinding.pathNode>();

            float   slopeX = (player.transform.position.y - transform.position.y) * 0.1f; //inverse 1 (slope), x and y are purposefuly backwards.
            float   slopeY = -(player.transform.position.x - transform.position.x);
            Vector2 a      = new Vector2(transform.position.x + slopeX * radius, transform.position.y + slopeY);
            Vector2 b      = new Vector2(transform.position.x - slopeX * radius, transform.position.y - slopeY);
            Debug.DrawLine(a, b, Color.red, 5f);

            for (int i = 0; i < nodes.Count; i++)
            {
                if (nodes[i].neighbours.Count > 2 &&
                    ((b.x - a.x) * (nodes[i].pos.y - a.y) - (b.y - a.y) * (nodes[i].pos.x - a.x)) > 0 &&
                    Mathf.Pow(transform.position.x - nodes[i].pos.x, 2) + Mathf.Pow(transform.position.y - nodes[i].pos.y, 2) <= Mathf.Pow(radius, 2) &&
                    Mathf.Pow(transform.position.x - nodes[i].pos.x, 2) + Mathf.Pow(transform.position.y - nodes[i].pos.y, 2) >= Mathf.Pow(innerRadius, 2))
                {
                    nodesInArea.Add(nodes[i]);
                }
            }

            if (nodesInArea.Count > 0)
            {
                Vector3 test = nodesInArea[Random.Range(0, nodesInArea.Count - 1)].pos;
                test.y += 0.5f;
                _pathAgent.RequestPath(test);
                _behaviourText.text = "Flee";
            }
            else
            {
                //could potentially run back into character, -- we can't run any further away in direction we want, so we pick a random point.

                for (int i = 0; i < nodes.Count; i++)
                {
                    if (nodes[i].neighbours.Count > 2 &&
                        Mathf.Pow(transform.position.x - nodes[i].pos.x, 2) + Mathf.Pow(transform.position.y - nodes[i].pos.y, 2) <= Mathf.Pow(radius, 2) &&
                        Mathf.Pow(transform.position.x - nodes[i].pos.x, 2) + Mathf.Pow(transform.position.y - nodes[i].pos.y, 2) >= Mathf.Pow(innerRadius, 2))
                    {
                        nodesInArea.Add(nodes[i]);
                    }
                }
                if (nodesInArea.Count > 0)
                {
                    Vector3 test = nodesInArea[Random.Range(0, nodesInArea.Count - 1)].pos;
                    test.y += 0.5f;
                    _pathAgent.RequestPath(test);
                    _behaviourText.text = "Flee";
                }
                else
                {
                    _behaviourText.text = "Can't Flee & Scared.";
                }
            }
        }
    }
コード例 #20
0
 public void UnFreeze()
 {
     state = EAIState.Idle;
 }
コード例 #21
0
 public void Freeze()
 {
     state = EAIState.Frozen;
 }
コード例 #22
0
 void Start()
 {
     state           = EAIState.Idle;
     damageIndicator = gameObject.GetComponent <DamageIndicator>();
 }
コード例 #23
0
ファイル: CheckAIState.cs プロジェクト: zyb2013/GameProject3
 public override void DrawNodeInspectorGUI()
 {
     base.DrawNodeInspectorGUI();
     this.ApplyAIState = (EAIState)UnityEditor.EditorGUILayout.EnumPopup("ApplyAIState", ApplyAIState);
 }
コード例 #24
0
        public EAIState GetEState(AIState state)
        {
            EAIState key = aiStates.FirstOrDefault(x => x.Value == state).Key;

            return(key);
        }
コード例 #25
0
 protected virtual void Die()
 {
     state = EAIState.Dead;
     Destroy(Instantiate(deathPoof, transform.position, Quaternion.identity), 2f);
     Destroy(gameObject);
 }
コード例 #26
0
 public AIState GetState(EAIState state)
 {
     return(aiStates[state]);
 }
コード例 #27
0
 public void UpdateState(EAIState state)
 {
     CurrentState = states.GetState(state);
 }
コード例 #28
0
 public void OnChangeState(EAIState state)
 {
     _state = state;
 }
コード例 #29
0
    // ---------------------------------------------------------------------
    // ---------------------------------------------------------------------

    #region Changing States
    private void ChangeState(EAIState _newState)
    {
        m_timeOnCurrentState = 0;
        m_currentState       = _newState;
    }
コード例 #30
0
 public void AggroOnPlayer()
 {
     state = EAIState.Aggro;
 }