private void Awake() { chaseState = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); wanderState = new WanderState(this); }
//--------------------------------------------------------------------------- void OnTriggerEnter2D(Collider2D otherCollider) { //If AI collides with reverseObjectName then Flip(): // reverse art facing and move direction if (otherCollider.gameObject.name == m_reverseObjectName && m_currentPigAlertState == AlertState.NotAlert) { FlipCurrentMovement(); Flip(); } if (otherCollider.gameObject.layer == 11) { FlipCurrentMovement(); Flip(); } if (otherCollider.gameObject.layer == 8 /* player */) { if (m_canSeePlayer) { m_currentPigAlertState = AlertState.CaughtPlayer; } else { if (!otherCollider.gameObject.GetComponent <PlayerController>().isMovingUp&& !otherCollider.gameObject.GetComponent <PlayerController>().isMovingDown) { FlipCurrentMovement(); Flip(); } } } }
public AIFSM(string name, EnemyController controller) : base(name, controller) { if (!controller) { // TODO: Add log LogHalt("EnemyController object null!"); Halt(); } #if UNITY_EDITOR LogThis = true; #endif idleState = new IdleState(this, EAIState.IDLE, "STATE_IDLE", controller); alertState = new AlertState(this, EAIState.ALERT, "STATE_ALERT", controller); aggressiveState = new AggressiveState(this, EAIState.AGGRESSIVE, "STATE_AGGRESSIVE", controller); idleState.AddTransition(new Tran_IdleToAlert(alertState, controller)); alertState.AddTransition(new Tran_AlertToAggressive(aggressiveState, controller)); alertState.AddTransition(new Tran_AlertToIdle(idleState, controller)); aggressiveState.AddTransition(new Tran_AggressiveToAlert(alertState, controller)); AddState(idleState); AddState(alertState); AddState(aggressiveState); }
public IStrategy Update(GameObject gameObject, AlertState alertState) { // The first waiter in the list of waiters calls animal control. // This only really works if the list is stable. WaiterAIComponent[] waiters = FindObjectsOfType <WaiterAIComponent>(); if (gameObject == waiters[0].gameObject) { return(new CallAnimalControlStrategy(gameObject)); } // Run toward the player. var player = GameObject.FindGameObjectWithTag("Player"); gameObject.GetComponent <Move>().MoveTowards(player); switch (alertState) { case AlertState.Relaxed: return(new RelaxedStrategy()); case AlertState.Alert: return(new AlertStrategy()); case AlertState.Aware: return(this); case AlertState.Escape: return(new EscapeStrategy()); case AlertState.Caught: case AlertState.GotAway: return(new PostGameStrategy()); default: return(this); } }
/// <summary> /// ���JS��ʾ��Ϣ�Ի��� /// </summary> /// <param name="context">ҳ��Context</param> /// <param name="Msg">��Ϣ����</param> /// <param name="Astate">���ģʽ * ö��</param> /// <param name="ToUrl">��ʾ��Ҫת����URL</param> public static void ShowAlert(HttpContext context, string Msg, AlertState Astate, string ToUrl) { System.Text.StringBuilder mySB = new System.Text.StringBuilder(); mySB.AppendFormat("<script type=\"text/javascript\">alert(\"{0}\");", Msg); switch (Astate) { case AlertState.Back: mySB.Append("history.go(-1);"); break; case AlertState.CloseWindow: mySB.Append("top.window.close();"); break; case AlertState.OpenInParentWindow: mySB.AppendFormat("top.location = '{0}';", ToUrl); break; case AlertState.OpenInThisWindow: mySB.AppendFormat("window.location = '{0}';", ToUrl); break; case AlertState.Nothing: break; } mySB.Append("</script>"); context.Response.Write(mySB.ToString()); }
private void SetState(AlertState newState) { switch (newState) { case AlertState.idlePatrol: if (alertState != AlertState.idlePatrol) { // TODO: pathPositions = pathfinding to targetPoint pathPositions.Clear(); } alertedIcon.transform.localScale = new Vector3(0, 0, 0); break; case AlertState.checkNoise: pathPositions.Clear(); // TODO: pathPositions = pathfinding to checkingNoisePosition pathPositions.Add(checkingNoisePosition); alertedIcon.color = Color.yellow; BumpAlertedIcon(); checkingWaitTime = 4.0f; break; case AlertState.attack: if (alertState != AlertState.attack) { alertedIcon.color = Color.red; BumpAlertedIcon(); } break; } alertState = newState; }
// The NPC has two states: FollowPath and ChasePlayer // If it's on the first state and SawPlayer transition is fired, it changes to ChasePlayer // If it's on ChasePlayerState and LostPlayer transition is fired, it returns to FollowPath private void MakeFSM() { FollowPathState follow = new FollowPathState(/*path*/); follow.AddTransition(Transition.SawPlayer, StateID.ChasingPlayer); ChasePlayerState chase = new ChasePlayerState(); chase.AddTransition(Transition.LostPlayer, StateID.FollowingPath); PatrolState patrolState = new PatrolState(PatrolWayPoints); patrolState.AddTransition(Transition.Alert, StateID.AlertNpc); AlertState alertState = new AlertState(); alertState.AddTransition(Transition.Attack, StateID.AttackingPlayer); alertState.AddTransition(Transition.Patrol, StateID.Patroling); AttackState attackState = new AttackState(); attackState.AddTransition(Transition.Alert, StateID.AlertNpc); fsm = new FSMSystem(); fsm.AddState(patrolState); fsm.AddState(alertState); fsm.AddState(attackState); //fsm.AddState(chase); //fsm.AddState(follow); Debug.Log("First State: " + fsm.CurrentState.ToString()); }
void Awake() { nMA = gameObject.GetComponent <NavMeshAgent> (); medBehaviour = gameObject.GetComponent <AlertState> (); medSounds = gameObject.GetComponent <MedusaSounds> (); beamThing = new Vector3(transform.position.x, transform.position.y + 2, transform.position.z); }
void Awake () { patrolState = new PatrolState(this); alertState = new AlertState(this); chaseState = new ChaseState(this); navMeshAgent = GetComponent<NavMeshAgent>(); }
public void SetAlert(AlertState alert) { alertState = alert; switch (alert) { case (AlertState.None): lights.SetActive(false); filter.SetActive(false); aSource.Stop(); break; case (AlertState.Yellow): lights.SetActive(true); filter.SetActive(true); aSource.pitch = 0.5f; aSource.Play(); SetColor(Color.yellow); break; case (AlertState.Red): lights.SetActive(true); filter.SetActive(true); aSource.pitch = 1f; aSource.Play(); SetColor(Color.red); break; } }
public void DetectNearestPlayer() { for (int i = 0; i < playersInConeAndInSight.Count; i++) { distToPlayer[i] = Vector3.Distance(playersInConeAndInSight[i].transform.position, transform.position); for (int j = i + 1; j < playersInConeAndInSight.Count; j++) { if ((distToPlayer[i] > distToPlayer[j]) && (i != j)) { GameObject tempGameObject; tempGameObject = playersInConeAndInSight[j]; playersInConeAndInSight[j] = playersInConeAndInSight[i]; playersInConeAndInSight[i] = tempGameObject; } } } //only give the nearest player if there are players in line of sight. if (playersInConeAndInSight.Count > 0) { closestPlayer = playersInConeAndInSight[0]; transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(playerDir), rotationSpeed * Time.deltaTime); } //else, return to normal state. else if (playersInConeAndInSight.Count <= 0) { alertState = AlertState.NORMAL; } }
public AlertStateChangeRequest(XServerId safeZoneId, XAccountId raiserId, XStringId alertId, AlertState newState) { SafeZoneId = safeZoneId; RaiserId = raiserId; AlertId = alertId; NewState = newState; }
private void Awake()//Before Start, initializes states and gets component reference for NavMeshAgent attached to enemy { chaseState = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>(); }
private void UpdateAlertState() { // Only update the alert state if it's below Escape. if (alertState >= AlertState.Escape) { return; } // Get the next state based on the alert level. If it hasn't changed, early out. var nextState = LevelToState(alertLevel); if (nextState == alertState) { return; } // Spawn the dog catcher when Escape begins. if (nextState == AlertState.Escape) { alertState = AlertState.Escape; dogText.text.text = "YOU MUST ESCAPE"; dogText.startTime = Time.time; var exit = GameObject.FindGameObjectWithTag("FrontDoor"); if (exit != null && dogCatcherPrefab != null) { Instantiate(dogCatcherPrefab, exit.transform.position, exit.transform.rotation); } } // The state is always allowed to go up. else if (nextState > alertState) { // Add half the threshold, to prevent rapid state transitions alertLevel = Threshold(nextState) + ((Threshold(nextState) - Threshold(alertState)) / 2); alertState = nextState; switch (alertState) { case AlertState.Alert: dogText.text.text = "THEY GROW SUSPICIOUS"; dogText.startTime = Time.time; break; case AlertState.Aware: dogText.text.text = "THEY KNOW YOU ARE DOG"; dogText.startTime = Time.time; break; default: break; } } // We can only transition down from Alert. Once they're aware, there's no going back. else if (alertState <= AlertState.Alert) { dogText.text.text = ""; alertState = nextState; } }
private void Awake() { seekState = new SeekState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); nav = GetComponent <NavMeshAgent> (); }
public override void Enter() { finishedLookingRight = false; orignalRotation = this.transform.rotation; lookRightRotation = new Quaternion(); statemachine = this.GetComponent <StateMachine> (); alertState = this.GetComponent <AlertState> (); }
private void Awake() { chaseTarget = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); navMeshAgent = GetComponent<NavMeshAgent>(); }
void Awake() { chaseState = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>(); }
private void Awake() { patrolState = new PatrolState(this); alertState = new AlertState(this); chaseState = new ChaseState(this); trackingState = new TrackingState(this); navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent>(); }
private float Threshold(AlertState state) { return (state >= AlertState.Escape ? thresholdEscape : state >= AlertState.Aware ? thresholdAware : state >= AlertState.Alert ? thresholdAlert : 0); }
private void Awake() { chaseState = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); navMeshAgent = GetComponent <NavMeshAgent> (); }
void Awake() { alertState = new AlertState(this); attackState = new AttackState(this); chaseState = new ChaseState(this); patrolState = new PatrolState(this); navMeshAgent = GetComponent <NavMeshAgent> (); }
private void Awake() { chaseState = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); aim = GetComponent<Aim>(); autoFire = GetComponent<AutoFire>(); }
void Awake() { engageState = new EngageState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); navMeshAgent = GetComponent <UnityEngine.AI.NavMeshAgent> (); currentState = patrolState; }
void Awake() { m_ChaseState = new ChaseState(this); m_AlertState = new AlertState(this); m_PatrolState = new PatrolState(this); m_NavMeshAgent = GetComponent <NavMeshAgent>(); }
public void Alert_Success_SetsCorrectStylesTest() { var alertState = new AlertState(); alertState.ApplyStyles("Success"); Assert.Equal("d-block alert alert-success", alertState.ResultClass); Assert.Equal("text-success", alertState.ResultSpan); }
private void Awake() { chaseState = new ChaseState(this); alertState = new AlertState(this); patrolState = new PatrolState(this); meshRendererFlag.GetComponent <Renderer>().enabled = true; this.eyes.GetComponent <sensor>().parent = this; this.initIa(); }
public void Alert_Warning_SetsCorrectStylesTest() { var alertState = new AlertState(); alertState.ApplyStyles("Warning"); Assert.Equal("d-block alert alert-warning", alertState.ResultClass); Assert.Equal("", alertState.ResultSpan); }
public void Alert_Error_SetsCorrectStylesTest() { var alertState = new AlertState(); alertState.ApplyStyles("Error"); Assert.Equal("d-block alert alert-danger", alertState.ResultClass); Assert.Equal("text-danger", alertState.ResultSpan); }
public async void Alert_Render_EndsWithHiddenDivTest() { var alertState = new AlertState(); await alertState.RenderVanishingAlertStylesAsync("Success", 2500); Assert.Equal("d-none", alertState.ResultClass); Assert.Equal("", alertState.ResultSpan); }
void OnTriggerEnter(Collider col) { if (col.CompareTag("Player")) { m_TargetPlayer = col.gameObject; m_AlertState = AlertState.Chasing; m_Agent.speed = m_ChaseSpeed; } }
void Awake() { // Tworzymy instancje każdego ze stanu // I przekazujemy do nich obiekt EnemyStates alertState = new AlertState(this); attackState = new AttackState(this); chaseState = new ChaseState(this); patrolState = new PatrolState(this); }
private AlertState() { if (_instance != null) { return; } _instance = this; }
public void StateChage(AlertState changeState) { state = changeState; if (state == AlertState.attacked) { StartCoroutine(ShowCrack()); } }
/// <summary> /// Sets the alert message and begins the fade in/out routine. /// </summary> /// <param name='message'> /// Alert message. /// </param> /// <param name='duration'> /// Duration to show message. /// </param> public override void SetMessage(string message, float duration) { if (!string.IsNullOrEmpty(message)) { alertDoneTime = DialogueTime.time + duration; if (line != null) line.text = FormattedText.Parse(message, DialogueManager.MasterDatabase.emphasisSettings).text; Show(); state = AlertState.Showing; TweenAlpha.Begin(line.gameObject, 0.2f, 1); } else { Hide(); state = AlertState.Hidden; } }
//--------------------------------------------------------------------------- void OnTriggerEnter2D(Collider2D otherCollider) { //If AI collides with reverseObjectName then Flip(): // reverse art facing and move direction if(otherCollider.gameObject.name == m_reverseObjectName && m_currentPigAlertState == AlertState.NotAlert) { FlipCurrentMovement(); Flip(); } if ( otherCollider.gameObject.layer == 11 ) { FlipCurrentMovement(); Flip(); } if (otherCollider.gameObject.layer == 8 /* player */) { if (m_canSeePlayer) { m_currentPigAlertState = AlertState.CaughtPlayer; } else { if ( !otherCollider.gameObject.GetComponent<PlayerController>().isMovingUp && !otherCollider.gameObject.GetComponent<PlayerController>().isMovingDown ) { FlipCurrentMovement(); Flip(); } } } }
//Called at every fixed framerate frame //Use when dealing with rigidBody Physics void FixedUpdate() { if (m_currentPigAlertState == AlertState.NotAlert) { switch (m_pigBehavior) { case PatrolBehaviors.Stationary: { // do nothing break; } case PatrolBehaviors.Flip: { FlipBehavior(); break; } case PatrolBehaviors.Patrol: { // do nothing break; } } } else { switch ( m_currentPigAlertState ) { case AlertState.ChasePlayer: { m_currentAlertStateTimer += Time.deltaTime; if ( m_currentAlertStateTimer >= m_secondsTilPlayerLost ) { m_currentAlertStateTimer = 0.0f; m_currentPigAlertState = AlertState.LostPlayer; m_hasPlayedAlertSound = false; } break; } case AlertState.LostPlayer: { m_currentAlertStateTimer += Time.deltaTime; if ( m_currentAlertStateTimer >= m_secondsTilBackToStart ) { m_currentAlertStateTimer = 0.0f; m_currentPigAlertState = AlertState.BackToStart; } break; } case AlertState.BackToStart: { //if ( m_currentDirection.x * transform.position.x >= m_currentDirection.x * m_pigHomePoint.x ) // if (transform.position.x == m_pigHomePoint.x) // { // // } break; } } } //-------------------------------------------------- // ***Moving Code*** //Set the rigidbody2D velocity so it can move //the object, if it's not dead rigidbody2D.velocity = m_movement; }
//--------------------------------------------------------------------------- public void Respawn() { transform.position = m_pigHomePoint; m_currentPigAlertState = AlertState.NotAlert; m_currentMoveDirection = m_initialMoveDirection; //m_isFacingRight = m_isFacingRightHolder; m_movement = new Vector2(0f, rigidbody2D.velocity.y); if (!m_isFacingRight || m_initialMoveDirection == PigInitialDirection.Left) Flip(); m_anim.SetBool("isAlert", false); m_anim.SetBool("caughtPlayer", false); this.gameObject.layer = 19; }
/// <summary> /// Fades out the alert line. /// </summary> /// <returns> /// IEnumerator (coroutine). /// </returns> /// <param name='FadedOutHandler'> /// Handler to call when finished fading out. /// </param> public IEnumerator FadeOut(Action FadedOutHandler) { state = AlertState.Fading; TweenAlpha.Begin(line.gameObject, fadeOutDuration, 0); yield return new WaitForSeconds(fadeOutDuration + 0.1f); // Wait 0.1s extra to allow TweenAlpha to close out. Hide(); state = AlertState.Hidden; if (FadedOutHandler != null) FadedOutHandler(); }
/// <summary> /// Get the various Components. /// Create the possible States.</summary> public virtual void Awake() { // Get the necessary Components _navMeshAgent = GetComponent<NavMeshAgent>(); _inventory = GetComponent<Inventory>(); // Initialize necessary properties _enemies = new List<Character>(); _interactingCharacters = new List<Character>(); // Initialize the Stats Stats = Instantiate(_stats); Stats.Character = this; // Initialize the States _idleState = new IdleState(this); _alertState = new AlertState(this); _chaseState = new ChaseState(this); _attackState = new AttackState(this); _dyingState = new DyingState(this); _moveState = new MoveState(this); }
// Update is called once per frame void Update () { //If not startEnabled freeze it this AI if ( m_pigBehavior == PatrolBehaviors.Patrol && m_currentPigAlertState == AlertState.NotAlert ) { //Set the movement variable m_movement = new Vector2 ( m_pigInitialMovementSpeed.x * m_currentDirection.x, rigidbody2D.velocity.y ); } else if ( m_currentPigAlertState == AlertState.ChasePlayer ) { if (!m_hasPlayedAlertSound) { PlaySound(m_alertSound); m_hasPlayedAlertSound = true; } m_movement = new Vector2 ( m_pigAlertMovementSpeed.x * m_currentDirection.x, rigidbody2D.velocity.y ); this.gameObject.layer = 20; m_anim.SetBool("isAlert", true); m_isFacingHomePoint = false; } else if ( m_currentPigAlertState == AlertState.LostPlayer ) { this.gameObject.layer = 19; m_anim.SetBool("isAlert", false); m_movement = new Vector2(0f, rigidbody2D.velocity.y); } else if ( m_currentPigAlertState == AlertState.CaughtPlayer ) { m_anim.SetBool("caughtPlayer", true); m_movement = new Vector2(0f, rigidbody2D.velocity.y); } else if ( m_currentPigAlertState == AlertState.BackToStart ) { if (!m_isFacingHomePoint) { float direction = m_pigHomePoint.x - transform.position.x; if ( ( direction < 0f && m_currentDirection.x > 0f ) || ( direction > 0f && m_currentDirection.x < 0f ) ) { Flip(); FlipCurrentMovement(); } m_isFacingHomePoint = true; } // float step = ( 0.5f * m_pigInitialMovementSpeed.x) * 2f * Time.deltaTime; // transform.position = Vector3.MoveTowards(transform.position, m_pigHomePoint, step); if ( m_currentDirection.x * ( m_pigHomePoint.x - transform.position.x ) <= 0f ) { m_currentPigAlertState = AlertState.NotAlert; m_movement = new Vector2(0f, rigidbody2D.velocity.y); m_currentMoveDirection = m_initialMoveDirection; if ((!m_isFacingRight && m_currentMoveDirection == PigInitialDirection.Right) || (m_isFacingRight && m_currentMoveDirection == PigInitialDirection.Left)) { //FlipCurrentMovement(); Flip(); } m_isFacingHomePoint = false; } else { m_movement = new Vector2 ( m_pigInitialMovementSpeed.x * m_currentDirection.x, 0f ); } } //Set the speed variable in our animator to our //x speed m_anim.SetFloat ("speed", Mathf.Abs (m_movement.x)); // Raycast for pig LOS RaycastHit2D hit = Physics2D.Raycast(transform.position, m_currentDirection, Mathf.Infinity, m_layerMask); if ( hit.collider.gameObject.tag == "Player" && m_currentPigAlertState != AlertState.CaughtPlayer ) { if ( hit.collider.gameObject.GetComponent<Player_Stealthed>().isLit ) { //Debug.DrawRay(transform.position, m_currentDirection * hit.distance, Color.white); m_currentPigAlertState = AlertState.ChasePlayer; m_currentAlertStateTimer = 0.0f; } } if ( hit.collider.gameObject.tag == "Player" && m_currentPigAlertState == AlertState.ChasePlayer) { m_canSeePlayer = true; } else { m_canSeePlayer = false; } }
/// <summary> /// Awake this instance. /// </summary> private void Awake() { GameObject pathFinding = GameObject.Find("Pathfinding"); enemy = GetComponent<HorrorAI>(); grid = pathFinding.GetComponent<Grid>(); enemySight = GetComponent<EnemySight> (); chaseState = new ChaseState(this, enemy); alertState = new AlertState(this, enemy); patrolState = new PatrolState(this, enemy, grid); pathfindingStrategy = "A*"; processedActions = new Queue<TreeAction>(); }