protected override void OnNPCSpawn() { //Banshee is by default Idlling, moves on agression or sight CurrentState = EAIState.ALIVE | EAIState.IDLE; m_HealthPoints = 100; }
private void Attack() { if (!CurrentState.HasFlag(EAIState.ATTACKING)) { CurrentState = CurrentState | EAIState.ATTACKING; } }
private void NotAttacking() { if (CurrentState.HasFlag(EAIState.ATTACKING)) { CurrentState -= EAIState.ATTACKING; } }
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("未知"); } }
public static void InvokeChangeStateEvent(EventData eventData, EAIState state) { if (ChangeStateEvent != null) { ChangeStateEvent(eventData, state); } }
public void ChangeAIState(EAIState pAIState) { if (AIState != pAIState) { AIState = pAIState; AIStateMachine.ChangeState(pAIState); } }
protected override void ChangeStateEventHandler(EventData eventData, EAIState state) { if (this.BehaviourObservesEvent(eventData) && state == _aiStateManagerBehaviour.GetAIState()) { base.ChangeStateEventHandler(eventData, state); OnFollowStart(); } }
protected override void ChangeStateEventHandler(EventData eventData, EAIState state) { if (this.BehaviourObservesEvent(eventData) && state == _stateBehaviour) { base.ChangeStateEventHandler(eventData, state); OnChase(); } }
public EMonster() : base() { AIState = EAIState.PATROL; SightDistance = 150; CanBeSeeDistance = 150; AutoAttackDistance = 5; LeaveCombatDistance = 10; }
public void MoveToState(EAIState pendingState) { if (_availiableStates [pendingState] != null) { _currentState.OnLeave(); _currentState = _availiableStates [pendingState]; _currentState.OnEnter(); } }
private void PathfindChase() { //Switch to chase if player in range if (PlayerInRange(6f, true)) { _pathAgent.pathfindingTarget = player; state = EAIState.chase; _behaviourText.text = "Chase"; } }
void Update() { //for debug testing only if (Input.GetKeyDown(KeyCode.V)) { CurrentState = CurrentState | EAIState.DYING; } if (!isLocalPlayer) { NPCDecision(); } if (CurrentState != previousState) { ChangeAnimations(); } }
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; } }
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; }
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; }
// 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(); }
public void BecomeIdle() { state = EAIState.Idle; }
private void Chase() { //Add this method into AiController _pathAgent.pathfindingTarget = player; state = EAIState.chase; _behaviourText.text = "Chase"; }
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."; } } } }
public void UnFreeze() { state = EAIState.Idle; }
public void Freeze() { state = EAIState.Frozen; }
void Start() { state = EAIState.Idle; damageIndicator = gameObject.GetComponent <DamageIndicator>(); }
public override void DrawNodeInspectorGUI() { base.DrawNodeInspectorGUI(); this.ApplyAIState = (EAIState)UnityEditor.EditorGUILayout.EnumPopup("ApplyAIState", ApplyAIState); }
public EAIState GetEState(AIState state) { EAIState key = aiStates.FirstOrDefault(x => x.Value == state).Key; return(key); }
protected virtual void Die() { state = EAIState.Dead; Destroy(Instantiate(deathPoof, transform.position, Quaternion.identity), 2f); Destroy(gameObject); }
public AIState GetState(EAIState state) { return(aiStates[state]); }
public void UpdateState(EAIState state) { CurrentState = states.GetState(state); }
public void OnChangeState(EAIState state) { _state = state; }
// --------------------------------------------------------------------- // --------------------------------------------------------------------- #region Changing States private void ChangeState(EAIState _newState) { m_timeOnCurrentState = 0; m_currentState = _newState; }
public void AggroOnPlayer() { state = EAIState.Aggro; }