private new void Start() { base.Start(); weapon_GrenadeLauncher.GetComponent <SpriteRenderer>().enabled = false; astarPathFinder = GetComponent <Astar>(); state = BehaviorState.Idle; }
public override NodeStatus OnBehave(BehaviorState state) { var context = (Context)state; if (context.Target == null) { return(NodeStatus.Failure); } if (AtDestination(context)) { return(NodeStatus.Success); } //Move for 120 ticks(4s) max if (_ticks > 240) { return(NodeStatus.Success); } _currentSpeed += 0.01f; context.Mover.SetSpeed(_currentSpeed); _ticks += 1; return(NodeStatus.Running); }
public void InitAddBehavior(BehaviorState behaviorState) { if (!mLisBehaviorStates.Contains(behaviorState)) { mLisBehaviorStates.Add(behaviorState); } }
private void Reset() { //Release the mouse capture AssociatedObject?.ReleaseMouseCapture(); _state = BehaviorState.Idle; }
void OnBehaviorStateExited(BehaviorState oldBehavior) { switch (oldBehavior) { case BehaviorState.Idle: break; case BehaviorState.Wander: break; case BehaviorState.Chase: // Stop forcing line of sight checks _perceptionComponent.ForceLineOfSightCheck = false; _perceptionComponent.ResetPlayerSpotTimer(); // Stop dropping player sanity while pursuit active GameStateManager.Instance.PlayerSanity.OnPursuitStopped(); break; case BehaviorState.Cower: break; case BehaviorState.Attack: break; case BehaviorState.Flee: break; case BehaviorState.Dead: break; } }
void Start() { IDLE_TARGET_LOC = new Vector3(-7.0f, 0.0f); TOP_SCREEN_LOC = new Vector3(-7.0f, 3.5f); boulderPooler = ObjectPooler.instance; sporePooler = ObjectPooler.instance; timer = IDLE_TIME; attacked = true; right = true; animator = GetComponent <Animator>(); boulderIndex = boulderPooler.GetIndex(boulderPrefab); sporeIndex = sporePooler.GetIndex(sporePrefab); if (boulderIndex == -1) { Debug.LogError("Boulder not found in object pooler"); boulderIndex = 0; } if (sporeIndex == -1) { Debug.LogError("Spore not found in object pooler"); sporeIndex = 0; } behaviorState = BehaviorState.Idle; direction = -1; attackTimer = DROP_ROCK_INTERVAL; corners = new Vector3[4]; corners[TOP_LEFT_IND] = new Vector3(-8.0f, 3.0f); corners[TOP_RIGHT_IND] = new Vector3(8.0f, 3.0f); corners[BOTTOM_RIGHT_IND] = new Vector3(8.0f, -3.0f); corners[BOTTOM_LEFT_IND] = new Vector3(-8.0f, -3.0f); currCornerInd = 0; cornersLen = corners.Length; lastAtk = LastAttack.None; }
// Ordered to follow void followOrder(GameObject player) { // TODO: Conditional denial, "Not now!" BehState = BehaviorState.Following; hardTarget = player; softTarget = new Vector2(0, 0); }
public void Update() { if (_enable && _entity != null && (_root.Reslut == BehaviorState.Reset || _root.Reslut == BehaviorState.Running)) { BehaviorState reslut = _root.Behave(_entity); switch (reslut) { case BehaviorState.Reset: break; case BehaviorState.Failure: break; case BehaviorState.Running: break; case BehaviorState.Success: break; default: _enable = false; LogUtil.LogUtility.PrintError("[BehaviorTree]error state."); break; } } }
public void Collided(ICollidable other) { if (other == _world) { //Console.WriteLine("Velocity " + _fsBody.LinearVelocity.Y); if (Math.Abs(_fsBody.LinearVelocity.Y) < 1 && behaviorState == BehaviorState.Flying) { this.behaviorState = BehaviorState.Walking; } else if (_fsBody.LinearVelocity.Y < -20 && behaviorState == BehaviorState.Flying) { this.behaviorState = BehaviorState.Dead; myCorpse.SetAnimationState(CivvieSprite.AnimationState.Dead); } if (this.behaviorState == BehaviorState.Dead) { _world.StopPhysicsing(_fsBody); } } if (other is CivvieController) { var otherCivvie = other as CivvieController; if (otherCivvie._fsBody.LinearVelocity.Length() > 50) { otherCivvie.Die(); this.Die(); } } }
BehaviorState UpdateBehavior_Wander() { BehaviorState nextBehavior = BehaviorState.Wander; // Spotted the player if (_perceptionComponent.CanSeePlayer) { nextBehavior = BehaviorState.Chase; } // Player was being "too noisy" behind us else if (_perceptionComponent.IsPlayerNearbyBehind) { if (PlayerCharacterController.Instance.IsSneaking) { nextBehavior = BehaviorState.Idle; } else { nextBehavior = BehaviorState.Chase; } } // Have we reached our path destination, chill for a bit else if (IsPathFinished || CantMakePathProgress) { nextBehavior = BehaviorState.Idle; } return(nextBehavior); }
public void Start(CSGameRoleBase role, BehaviorState lastState) { if (mDelStart != null) { mDelStart(role, lastState); } }
// process noises, TODO: trigger zombie engagement! void HearNoise(Noise noise) { if (noise.gameObject != null) { if (noise.gameObject != gameObject && noise.gameObject.tag == "Zombie") // If a zombie made the noise { Vector2 loc = noise.location; int vol = noise.volume; // scale response based upon distance away float dist = Vector2.Distance(loc, transform.position); float intensity = 3 * vol * (1 / (3 + dist)); // grows with lower distance, and with higher volume if ((dist < engagementRange) && (intensity > targetIntensity)) { // TODO: Trigger fighting mode with a specific hard target if (noise.gameObject != hardTarget) { print("new HT: " + noise.gameObject + " at " + Time.fixedTime + " seconds."); } hardTarget = noise.gameObject; // we have a hard target BehState = BehaviorState.Fighting; targetIntensity = intensity; } else { // noise doesnt matter to us } } } }
private void RepalceData(string name, BehaviorState state) { foreach (PlayerBehaviourIndex behaviourIndex in Enum.GetValues(typeof(PlayerBehaviourIndex))) { RepalceData(name, behaviourIndex, state); } }
private void UpdateIdle() { if (10 < 15) { m_State = BehaviorState.Attack; } }
// -----------------------------------------------------------------------------------------------------// // Decides what behavior the human should be in right now // If we see encounter an enemy, switch to fighting state. // If player requests to talk, and we are not busy, go to talking state. // If player asks us to follow, go to follow state, set target to near player (not bumping into them) // If player tells us to hide, go to hiding state. // If player tells us to rest, go to resting state. // If player tells us to loot, go to looting state. // If player tells us to flee, or if danger is high, go to fleeing state // // Someone requests to talk void talkRequest(GameObject player) { // TODO: Dont always listen to request! Not now! BehState = BehaviorState.Talking; hardTarget = player; softTarget = player.transform.position; }
public override ActionResult Execute(AIPawn pawn) { BehaviorState behavior = pawn.BehaviorState; List <Point> adjacentPoints = pawn.Position.Adjacent(); var adjacentPointsWithEnemy = new List <Point>(); foreach (Point adjacentPoint in adjacentPoints) { if (BattleController.Instance.Player.IsPawnOnPoint(adjacentPoint)) { adjacentPointsWithEnemy.Add(adjacentPoint); } } behavior.PointOptions = adjacentPointsWithEnemy; if (behavior.PointOptions.Count <= 0) { return(ActionResult.Failure); } return(ActionResult.Success); }
// 转换行为状态到生物状态 static public BeingState convBehaviorState2BeingState(BehaviorState behaviorState) { BeingState retState = BeingState.BSIdle; switch (behaviorState) { case BehaviorState.BSIdle: { retState = BeingState.BSIdle; } break; case BehaviorState.BSWander: { retState = BeingState.BSWalk; } break; case BehaviorState.BSFollow: { retState = BeingState.BSWalk; } break; } return(retState); }
// Ordered to loot surrounding areas void lootOrder(GameObject player) { // TODO: Conditional denial, "Not now!" BehState = BehaviorState.Looting; softTarget = player.transform.position; // set general location to be where player is standing hardTarget = GAMESTATE.findNearestLoot(gameObject); // TODO: Find hard target items later! }
/* Instance Methods */ public override void Awake() { base.Awake(); canMove = true; normal = new BehaviorState("normal", this.normal_update, this.normal_fupdate, this.lupdate); passive = new BehaviorState("passive", this.passive_update, this.passive_fupdate, this.lupdate); recording = new BehaviorState("recording", this.recording_update, this.recording_fupdate, this.lupdate); playing = new BehaviorState("playing", this.playing_update, this.playing_fupdate, this.lupdate); setState(normal); direction = Vector2.zero; updateInputs = new Timeline <KeyCode>(); fixedInputs = new Timeline <KeyCode> (); fixedInputs.setLooping(true); updateInputs.setLooping(true); clone = null; selfPref = Resources.Load <GameObject> ("Player"); replayStartPos = Vector3.zero; replayStartRot = Quaternion.identity; }
/* ########################## State defining actions ############################ */ public Action ApproachEnemy() { unit_state.agent.avoidancePriority = 20; current_behavior_state = BehaviorState.Approach; unit_state.agent.SetDestination (unit_state.tracked_enemy.transform.position); yield return NodeResult.Success; }
protected void ChangeState(BehaviorState state) { if (GetState() == BehaviorState.FALLING) { return; } switch (state) { case BehaviorState.IDLE: OnChangeToIdle(); break; case BehaviorState.WALKING: OnChangeToWalking(); break; case BehaviorState.CONFUSED: OnChangeToConfused(); break; case BehaviorState.NOTICED: OnChangeToNoticed(); break; case BehaviorState.SLIPPING: OnChangeToSlipping(); break; case BehaviorState.FALLING: OnChangeToFalling(); break; } currentBehavior = state; Debug.Log("Current State = " + currentBehavior); }
BehaviorState UpdateBehavior_Idle() { BehaviorState nextBehavior = BehaviorState.Idle; // Give player some extra time if they are sneaking behind us bool isPlayerSneaking = PlayerCharacterController.Instance.IsSneaking; float idleTimeout = _perceptionComponent.IsPlayerNearbyBehind ? IdleMaxDuration : _idleDuration; // Spotted the player if (_perceptionComponent.CanSeePlayer) { nextBehavior = BehaviorState.Chase; } // Player was being "too noisy" behind us else if (_perceptionComponent.IsPlayerNearbyBehind && !isPlayerSneaking) { nextBehavior = BehaviorState.Chase; } // Been in idle too long, go somewhere else else if (_timeInBehavior >= idleTimeout) { nextBehavior = BehaviorState.Wander; } return(nextBehavior); }
public void End(CSGameRoleBase role, BehaviorState nextState) { if (mDelEnd != null) { mDelEnd(role, nextState); } }
public void Start() { // 獲取動畫 _animator = GetComponent <Animator>(); // 如果人物寬度是正的,朝向右 _isFacingRight = transform.localScale.x > 0; _originalGravity = _controller.Parameters.Gravity; CurrentHealth = BehaviorParameters.MaxHealth; // 初始化控制器的所有狀態為默認值 BehaviorState.Initialize(); BehaviorState.NumberOfJumpsLeft = BehaviorParameters.NumberOfJumps; isMoving = false; //是否有移動 OriginalPos = gameObject.transform.position; //先記錄原先位置 BehaviorState.CanJump = true; BuffTime = 0; OriginTag = gameObject.tag; canMove = true; _playersc = gameObject.GetComponent <playerScript>(); if (gameObject.layer == 9) { _check = GameObject.Find("HumanRespawnPos").GetComponent <CheckPoint>(); } else if (gameObject.layer == 13) { _check = GameObject.Find("MonsterRespawnPos").GetComponent <CheckPoint>(); } }
/// <summary> /// Iterates through child nodes. /// Breaks exectution on Success, pauses execution on Running, return Failure if all children fail. /// </summary> /// <returns>Node State</returns> protected override BehaviorState UpdateNode() { while (ChildIndex < ChildNodes.Count) { BehaviorState NodeState = ChildNodes[ChildIndex].RunNode(); if (NodeState == BehaviorState.Success) { // Reset Iterator ChildIndex = 0; return(BehaviorState.Success); } if (NodeState == BehaviorState.Running) { // Keep Iterator return(BehaviorState.Running); } if (NodeState == BehaviorState.Error) { // TODO: Debug friendly error. return(BehaviorState.Error); } // Iterate ChildIndex++; } // Reset Iterator ChildIndex = 0; return(BehaviorState.Failure); }
public virtual NodeStatus Behave(BehaviorState state) { // TODO: Checking conditionals every tick hits performance if (_status != NodeStatus.Running) { OnEnter(state); } if (ShowDebug) { Debug.Log("OnBehave " + Name); } _status = OnBehave(state); if (_status != NodeStatus.Running) { OnExit(state); } if (ShowDebug) { Debug.Log("Return " + Name + " = " + _status.ToString()); } return(_status); }
public void Switch2(int switchState, bool isNotReset) { BehaviorState behavior = GetBehavior(switchState); if (behavior != null) { ResetWait(); if (behavior == mCurrentBehavior) { if (!isNotReset) { mCurrentBehavior.End(mRole, mCurrentBehavior); mCurrentBehavior.Start(mRole, mCurrentBehavior); } } else { if (mCurrentBehavior != null) { mCurrentBehavior.End(mRole, behavior); } BehaviorState lastBehavior = mCurrentBehavior; mCurrentBehavior = behavior; mCurrentBehavior.Start(mRole, lastBehavior); } } }
protected MovableEntity(SerializationInfo info, StreamingContext context) : base(info, context) { m_actorState = (BehaviorState)info.GetValue("actorState", typeof(BehaviorState)); m_positionMemento = (ActorPositionMemento)info.GetValue("positionMemento", typeof(ActorPositionMemento)); m_velocity = (Vector3)info.GetValue("velocity", typeof(Vector3)); m_speed = info.GetSingle("speed"); }
private void Start() { m_Targetable.enabled = false; m_SpellActive.enabled = false; m_Text.enabled = false; m_IsDead = false; // Position m_State = BehaviorState.Idle; m_InitialePos = transform.position; m_EnemyAgent = GetComponent <NavMeshAgent>(); // Health m_CurrentHealth = m_EnemyData.EnemyMaxHealth; m_HealthBar.value = 1; m_HealthBar.gameObject.SetActive(false); SetZoneStats(); m_Animator.SetTrigger("Idle"); // Starting pos feedback GameObject Ring = Instantiate(m_RingOfFire, transform, false); StartCoroutine(EndRing(Ring)); }
// Ordered to rest or hold position void restOrder(GameObject player) { // TODO: Conditional denial, "Not now!" BehState = BehaviorState.Resting; softTarget = transform.position; hardTarget = null; }
public void Update(float interval) { if (Enable && Entity != null && (Root.Reslut == BehaviorState.Reset || Root.Reslut == BehaviorState.Running)) { BehaviorState reslut = Root.Behave(Entity, interval); switch (reslut) { case BehaviorState.Reset: break; case BehaviorState.Failure: break; case BehaviorState.Running: break; case BehaviorState.Success: break; case BehaviorState.Finish: break; default: Enable = false; LogHelper.PrintError("[BehaviorTree]error state."); break; } } }
private void SetStateIdle() { state = BehaviorState.Idle; animator.SetBool("isMoving", false); ResetStateTime(); }
public void toggleBehavior(BehaviorState bs) { if (m_behaviorTree.inputParam.beingEntity.aiLocalState.behaviorState != bs) { m_behaviorTree.inputParam.beingEntity.aiLocalState.behaviorState = bs; onEnter(); } }
public void ChangeStateTo(BehaviorState targetState) { if (state == BehaviorState.Idle && targetState == BehaviorState.Patrolling) { SeekNewPosition(); } else if (state == BehaviorState.Patrolling && targetState == BehaviorState.Attacking) { pathAgentController.Stop(); } state = targetState; }
/* public Action TryFindingBetterCombatPosition () { // get potential good combat position // if ( found ) return Failure yield return NodeResult.Success; } */ public Action Attack() { unit_state.agent.Stop (); unit_state.agent.velocity = Vector3.zero; if (unit_state.type == UnitType.Melee) unit_state.agent.avoidancePriority = 6; if (unit_state.type == UnitType.Ranger) unit_state.agent.avoidancePriority = 10; //GetComponent<NavMeshObstacle> ().enabled = true; current_behavior_state = BehaviorState.Attack; yield return NodeResult.Success; }
/* ########################## State defining actions ############################ */ public Action ApproachEnemy() { debug.Log (showDebug, 20, "ApproachEnemy"); OnSteering = false; CancelInvoke (); current_behavior_state = BehaviorState.Approach; if (core.HasTrackedEnemy ()) { //if ( !core.agent.isActiveAndEnabled ) core.agent.enabled = true; //core.agent.avoidancePriority = 20; core.agent.SetDestination (core.tracked_enemy.transform.position); //core.agent.Resume(); } yield return NodeResult.Success; }
public Action Attack() { debug.Log (showDebug, 22, "Attack"); core.agent.Stop (); //core.agent.velocity = Vector3.zero; //if (core.type == UnitType.Melee) //core.agent.avoidancePriority = 6; //if (core.type == UnitType.Ranger) //core.agent.avoidancePriority = 10; current_behavior_state = BehaviorState.Attack; yield return NodeResult.Success; }
/// <summary> /// Creates a new instance of an enemy beam ship /// </summary> /// <param name="content">A ContentManager to load resources with</param> /// <param name="position">The position of the beam ship in the game world</param> public BeamShip(uint id, ContentManager content, Vector2 position) : base(id) { this.position = position; weaponAlive = true; shipAlive = true; weaponFiring = false; behaviorState = BehaviorState.Flying; damageState = DamageState.Healthy; velocityY = new Vector2(0, 35); velocityX = new Vector2(80, 0); timer = -1; spritesheet = content.Load<Texture2D>("Spritesheets/newsh2.shp.000000"); //load the body of the craft from the spritesheet spriteBounds[(int)BeamShipParts.Body].X = 100; spriteBounds[(int)BeamShipParts.Body].Y = 55; spriteBounds[(int)BeamShipParts.Body].Width = 37; spriteBounds[(int)BeamShipParts.Body].Height = 28; drawBounds[(int)BeamShipParts.Body] = new Rectangle((int)position.X, (int)position.Y, spriteBounds[(int)BeamShipParts.Body].Width, spriteBounds[(int)BeamShipParts.Body].Height); //load the weapon for the craft from the sprite sheet spriteBounds[(int)BeamShipParts.Weapon].X = 107; spriteBounds[(int)BeamShipParts.Weapon].Y = 84; spriteBounds[(int)BeamShipParts.Weapon].Width = 24; spriteBounds[(int)BeamShipParts.Weapon].Height = 28; drawBounds[(int)BeamShipParts.Weapon] = new Rectangle((int)(position.X + weaponOffset.X), (int)(position.Y + weaponOffset.Y), spriteBounds[(int)BeamShipParts.Weapon].Width, spriteBounds[(int)BeamShipParts.Weapon].Height); //load the weapon's fire animation from the sprite sheet beamSpriteSheet = content.Load<Texture2D>("Spritesheets/newsh(.shp.000000"); spriteBounds[(int)BeamShipParts.WeaponFire].X = 13; spriteBounds[(int)BeamShipParts.WeaponFire].Y = 70; spriteBounds[(int)BeamShipParts.WeaponFire].Width = 11; spriteBounds[(int)BeamShipParts.WeaponFire].Height = 11; drawBounds[(int)BeamShipParts.WeaponFire] = new Rectangle((int)(position.X + weaponFireOffset.X), (int)(position.Y + weaponFireOffset.Y), spriteBounds[(int)BeamShipParts.WeaponFire].Width, spriteBounds[(int)BeamShipParts.WeaponFire].Height); }
protected new virtual void Start() { base.Start(); internalAttackTimer = 0.0f; this.currentState = BehaviorState.Passive; }
/* checks the condition for a given behavior, easier to manage as these condition are used in multiple places */ private bool checkBehavior(List<Behavior> behaviors, BehaviorState target) { switch (target) { case BehaviorState.SelfDestruct: return (distance < selfDestructDistance); case BehaviorState.Shoot: return (parent.Timer.elapsedMilliseconds() > parent.BulletType[parent.bulletSelection].BulletInterval) && canShoot(parent.Behaviors); case BehaviorState.Evade: return (distance < evadeDistance - hysteresis); case BehaviorState.Chase: return (distance > chaseDistance + hysteresis); } return false; }
/// <summary> /// Updates the beam ship /// </summary> /// <param name="elapsedTime">The in-game time between the previous and current frame</param> public override void Update(float elapsedTime) { // Sense the player's position PlayerShip player = ScrollingShooterGame.Game.Player; Vector2 playerPosition = new Vector2(player.Bounds.Center.X, player.Bounds.Center.Y); if (timer > 0) timer -= elapsedTime; switch (behaviorState) { case BehaviorState.Flying: this.position += velocityY * elapsedTime; if (timer < 0) { if (this.position.X >= playerPosition.X - 23 && this.position.X <= playerPosition.X + 23 && this.position.Y < playerPosition.Y) { timer = 1f; behaviorState = BehaviorState.Charging; } } break; case BehaviorState.Charging: weaponFiring = true; if(timer < .9) behaviorState = BehaviorState.Firing; break; case BehaviorState.Firing: if (weaponAlive) { ScrollingShooterGame.GameObjectManager.CreateProjectile(ProjectileType.BlueBeam, new Vector2(this.position.X + weaponFireOffset.X + 1, this.position.Y + weaponFireOffset.Y + 8)); weaponFiring = false; behaviorState = BehaviorState.Flying; } else behaviorState = BehaviorState.Fleeing; break; case BehaviorState.Fleeing: this.position += velocityY * elapsedTime; if (position.X >= ScrollingShooterGame.Game.GraphicsDevice.Viewport.Bounds.Center.X) this.position += velocityX * elapsedTime; else this.position -= velocityX * elapsedTime; break; case BehaviorState.Fragged: //the code for the ship dying will go here break; } switch (damageState) { case DamageState.Healthy: if (weaponHealth <= 0) { weaponAlive = false; damageState = DamageState.WeaponBroke; behaviorState = BehaviorState.Fleeing; } break; case DamageState.WeaponBroke: if (shipHealth <= 0) { damageState = DamageState.Dead; behaviorState = BehaviorState.Fragged; } break; case DamageState.Dead: shipAlive = false; //need code for dead ship break; } drawBounds[(int)BeamShipParts.Body] = new Rectangle((int)position.X, (int)position.Y, spriteBounds[(int)BeamShipParts.Body].Width, spriteBounds[(int)BeamShipParts.Body].Height); drawBounds[(int)BeamShipParts.Weapon] = new Rectangle((int)(position.X + weaponOffset.X), (int)(position.Y + weaponOffset.Y), spriteBounds[(int)BeamShipParts.Weapon].Width, spriteBounds[(int)BeamShipParts.Weapon].Height); drawBounds[(int)BeamShipParts.WeaponFire] = new Rectangle((int)(position.X + weaponFireOffset.X), (int)(position.Y + weaponFireOffset.Y), spriteBounds[(int)BeamShipParts.WeaponFire].Width, spriteBounds[(int)BeamShipParts.WeaponFire].Height); }
public Action MoveAlongPath() { if (unit_state.type == UnitType.Melee) unit_state.agent.avoidancePriority = 4; if (unit_state.type == UnitType.Ranger) unit_state.agent.avoidancePriority = 5; current_behavior_state = BehaviorState.MoveAlongPath; if ( unit_state.current_node != null ) unit_state.agent.SetDestination (unit_state.current_node.real_transform.position); unit_state.agent.Resume (); yield return NodeResult.Success; }
public void FindTarget(ResourceType resource, BehaviorState newState) { pursueTarget = foodMap.FindClosestResource(resource, transform.position, stateMachine.myType); myState = newState; }
public Action DoApproachEnemy() { var dif = last_approach_pos - unit_state.tracked_enemy.transform.position; if (dif.magnitude > unit_state.parameters.attack_range) { last_approach_pos = unit_state.tracked_enemy.transform.position; unit_state.agent.ResetPath(); unit_state.agent.SetDestination (last_approach_pos); } else { _appr_timer += reactor.TickDuration; if ( _appr_timer > 2f ) { if ( !unit_state.agent.pathPending ) { if ( unit_state.agent.pathStatus == NavMeshPathStatus.PathComplete | unit_state.agent.pathStatus == NavMeshPathStatus.PathPartial ) { if ( !IsTrackedEnemyInRange() ) { _appr_timer = 0; var e = GetClosestActiveEnemy (); if ( e == unit_state.tracked_enemy ) { e = GetAnotherCloseActiveEnemy(unit_state.tracked_enemy); } if (e != null) { unit_state.tracked_enemy = e; tracked_enemy_id = e.id; unit_state.agent.ResetPath(); last_approach_pos = e.transform.position; unit_state.agent.SetDestination(last_approach_pos); unit_state.agent.avoidancePriority = 9; } else { //unit_state.agent.Stop(); //unit_state.agent.velocity = Vector3.zero; //unit_state.agent.avoidancePriority = 60; current_behavior_state = BehaviorState.MoveAlongPath; if ( unit_state.current_node != null ) unit_state.agent.SetDestination (unit_state.current_node.real_transform.position); unit_state.agent.Resume (); unit_state.tracked_enemy = null; } } } } } } yield return NodeResult.Success; }
public void ProcessBehavior(GameTime time) { if (Math.Abs(_fsBody.LinearVelocity.Y) > 1 && behaviorState != BehaviorState.Dead) { behaviorState = BehaviorState.Flying; myCorpse.SetAnimationState(CivvieSprite.AnimationState.Flying); } if (behaviorState == BehaviorState.Walking) { myCorpse.SetAnimationState(CivvieSprite.AnimationState.WalkingLeft); _fsBody.LinearVelocity = new Vector2(-20, _fsBody.LinearVelocity.Y); _fsBody.Rotation = 0; } }
public void ProcessBehavior(GameTime time) { this.patrolAccumulator += time.ElapsedGameTime; this.shootAccumulator += time.ElapsedGameTime; if (Math.Abs(_fsBody.LinearVelocity.Y) > 1 && behaviorState != BehaviorState.Dead) { behaviorState = BehaviorState.Flying; copSprite.SetAnimationState(CopSprite.AnimationState.Flying); } //patrols else if (behaviorState == BehaviorState.PatrollingLeft) { copSprite.SetAnimationState(CopSprite.AnimationState.WalkingLeft); _fsBody.LinearVelocity = new Vector2(-20, _fsBody.LinearVelocity.Y); CheckPatrolPattern(); } else if (behaviorState == BehaviorState.PatrollingRight) { copSprite.SetAnimationState(CopSprite.AnimationState.WalkingRight); _fsBody.LinearVelocity = new Vector2(20, _fsBody.LinearVelocity.Y); CheckPatrolPattern(); } //shooting else if (behaviorState == BehaviorState.Aiming) { copSprite.SetAnimationState(CopSprite.AnimationState.Aiming); this._fsBody.LinearVelocity = new Vector2(0, _fsBody.LinearVelocity.Y); this.aimAccumulator += time.ElapsedGameTime; if (aimAccumulator > this.aimTimer) { behaviorState = BehaviorState.Shooting; aimAccumulator = TimeSpan.Zero; aimTimer = TimeSpan.FromSeconds(VERGEGame.rand.Next(1, 5)); } } else if (behaviorState == BehaviorState.Shooting) { copSprite.SetAnimationState(CopSprite.AnimationState.Shooting); copSprite.animationAtlas[CopSprite.AnimationState.Shooting].OnEnd = (Filmstrip fs) => { CheckPatrolPattern(); if (behaviorState != BehaviorState.Shooting) { spawnBullet(); } return fs.FinishProcessAnimation(1); }; } }
public void Collided(ICollidable other) { if (other == _world) { //Console.WriteLine("Velocity " + _fsBody.LinearVelocity.Y); if (Math.Abs(_fsBody.LinearVelocity.Y) < 1 && behaviorState == BehaviorState.Flying) { CheckPatrolPattern(); } else if (_fsBody.LinearVelocity.Y < -20 && behaviorState == BehaviorState.Flying) { this.behaviorState = BehaviorState.Dead; copSprite.SetAnimationState(CopSprite.AnimationState.Dead); } } if (other is CivvieController) { var otherCivvie = other as CivvieController; if (otherCivvie._fsBody.LinearVelocity.Length() > 50) { otherCivvie.Die(); this.Die(); } } }
private void CheckPatrolPattern() { if (shootAccumulator > shootTimer) { shootAccumulator = TimeSpan.Zero; shootTimer = TimeSpan.FromSeconds(VERGEGame.rand.Next(5, 15)); if (_fsBody.Position.X < playerPosition.X) { behaviorState = BehaviorState.Aiming; } } else if (patrolAccumulator > this.patrolDuration) { patrolAccumulator = TimeSpan.Zero; if (behaviorState == BehaviorState.PatrollingLeft) { behaviorState = BehaviorState.PatrollingRight; } else if (behaviorState == BehaviorState.PatrollingRight) { behaviorState = BehaviorState.PatrollingLeft; } else { bool goLeft = VERGEGame.rand.Next(0, 2) == 0; behaviorState = goLeft ? BehaviorState.PatrollingLeft : BehaviorState.PatrollingRight; } this.patrolDuration = TimeSpan.FromSeconds(VERGEGame.rand.Next(3, 7)); } }
private void Die() { this.behaviorState = BehaviorState.Dead; copSprite.SetAnimationState(CopSprite.AnimationState.Dead); }
private void shoot(Map map, GameTime gameTime) { PlaneObj target = map.hero; Behavior behavior = null; /* h = hero; 1 = parent is at this location and uses first the if statement, 2 the second * ------------- * | h | h | h | * +---+---+---+ * | 1 | 2 | 1 | * +---+---+---+ * | 1 | 2 | 1 | * ------------- */ if (yDistance > _GLOBAL.Viewport.Height / 6) // hero is in the back { if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 3) // hero is left or right { behavior = firstBehaviorfirstGet(parent.Behaviors, BehaviorState.ShootCircle, BehaviorState.ShootTarget, BehaviorState.ShootStraightAngle, BehaviorState.ShootStraight); if (_GLOBAL.Debug) Console.WriteLine("top left/right"); } else // hero is in range { behavior = firstBehaviorfirstGet(parent.Behaviors, BehaviorState.ShootStraightAngle, BehaviorState.ShootCircle, BehaviorState.ShootTarget, BehaviorState.ShootStraight); if (_GLOBAL.Debug) Console.WriteLine("top mid"); } } /* h = hero; 1 = parent is at this location and uses first the if statement, 2 the second * ------------- * | | | | * +---+---+---+ * |h1 |h2 |h1 | * +---+---+---+ * | | | | * ------------- */ else if (yDistance <= _GLOBAL.Viewport.Height / 3 && yDistance >= -_GLOBAL.Viewport.Height / 6) // hero is within range { if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 6) // hero is left or right { behavior = firstBehaviorfirstGet(parent.Behaviors, BehaviorState.ShootTarget, BehaviorState.ShootStraightAngle, BehaviorState.ShootCircle, BehaviorState.ShootStraight); if (_GLOBAL.Debug) Console.WriteLine("mid left/right"); } else { behavior = firstBehaviorfirstGet(parent.Behaviors, BehaviorState.ShootCircle, BehaviorState.ShootStraight, BehaviorState.ShootStraightAngle, BehaviorState.ShootTarget); if (_GLOBAL.Debug) Console.WriteLine("mid mid"); } } /* h = hero; 1 = parent is at this location and uses first the if statement, 2 the second * ------------- * | 1 | 2 | 1 | * +---+---+---+ * | 1 | 2 | 1 | * +---+---+---+ * | h | h | h | * ------------- */ else if (yDistance < -_GLOBAL.Viewport.Height / 6) // hero is in the front { if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 6) // hero is left or right { behavior = firstBehaviorfirstGet(parent.Behaviors, BehaviorState.ShootTarget, BehaviorState.ShootStraightAngle, BehaviorState.ShootCircle, BehaviorState.ShootStraight); if (_GLOBAL.Debug) Console.WriteLine("bot left/right"); } else { behavior = firstBehaviorfirstGet(parent.Behaviors, BehaviorState.ShootStraight, BehaviorState.ShootCircle, BehaviorState.ShootStraightAngle, BehaviorState.ShootTarget); if (_GLOBAL.Debug) Console.WriteLine("bot mid"); } } if (behavior != null) { behavior.Update(map, gameTime); lastShooting = behavior.behaviorState; } }
protected virtual void Update() { /** If not passive, start counting down until becoming passive. **/ if (stateTimer > 0.0f) { stateTimer -= Time.deltaTime; } else if(this.currentState == BehaviorState.Alerted || this.currentState == BehaviorState.Restless) { this.currentState = BehaviorState.Passive; stateTimer = 0.0f; playerHeard = false; AlarmManager.Get().TurnOffAlarm(); } // Alerted = chasing if(this.currentState == BehaviorState.Alerted) { Chasing(); } // Otherwise patrol. else { Patrolling(); } if (AlarmManager.Get().isAlarmSounding) { // I am alert. this.currentState = BehaviorState.Alerted; } }
public Action WaitInPosition() { current_behavior_state = BehaviorState.WaitInPosition; yield return NodeResult.Success; }
// check things that enter vision void OnTriggerEnter(Collider collider) { // Create a vector from the enemy to the player and store the angle between it and forward. Vector3 direction = transform.position - collider.transform.position; float angle = Vector3.Angle(direction, transform.forward); // If the angle between forward and where the object is, is less than half the angle of view... if (angle < this.visionAngle * 0.5f) { // Object in view is player if (collider.tag.Equals("Player")) { // The player is in sight. if (this.currentState != BehaviorState.Alerted) { // become alerted and increase state timer. this.currentState = BehaviorState.Alerted; stateTimer = 20.0f; } } // Object in view is another enemy else if (collider.tag.Equals("Enemy")) { // dead body checking if(collider.gameObject.GetComponent<Enemy>().IsDead() && this.currentState != BehaviorState.Alerted) { // If not Alerted become restless and increase state timer. this.currentState = BehaviorState.Restless; stateTimer = 45.0f; } } } // hearing detection if (playerReference.GetComponent<PlayerControl>().state == "run") { if (!playerHeard && this.currentState == BehaviorState.Passive) { playerHeard = true; // If not Alerted become restless and increase state timer. this.currentState = BehaviorState.Restless; stateTimer += 15.0f; } } }
private void controlBehavior(Map map, GameTime gameTime) { PlaneObj target = map.hero; Behavior behavior = null; foreach (Behavior b in parent.Behaviors) { /* If the object has waypoints to go, ignore other behaviors; waypoints are prioritized */ if (b.behaviorState == BehaviorState.LinearBehavior) { if (parent.Path.Count > 0) behavior = b; } } if (behavior == null) { /* These if-statements can be reduced, but this is more readable. At lease, for me it is. */ if (yDistance > _GLOBAL.Viewport.Height / 6) // hero is in the back { if (xDistance > _GLOBAL.Viewport.Width / 6 || xDistance < -_GLOBAL.Viewport.Width / 6) // hero is left or right of parent behavior = routineB(); else // hero is nearby behavior = routineA(); } else if (yDistance <= _GLOBAL.Viewport.Height / 6 && yDistance >= -_GLOBAL.Viewport.Height / 6) // hero is nearby behavior = routineA(); else if (yDistance < -_GLOBAL.Viewport.Height / 6) // hero is in the front behavior = routineB(); } else { /* if the hero has waypoints to move, but it can shoot as well. Shooting is prioritized */ if (parent.Timer.elapsedMilliseconds() > parent.BulletType[parent.bulletSelection].BulletInterval) { foreach (Behavior b in parent.Behaviors) if (b.behaviorState == BehaviorState.Shoot && canShoot(parent.Behaviors)) behavior = b; parent.Timer.reset(); } } if (behavior != null) { if (_GLOBAL.Debug) Console.WriteLine(behavior.ToString()); behavior.Update(map, gameTime); lastBehavior = behavior.behaviorState; } }
internal void Die() { this.behaviorState = BehaviorState.Dead; myCorpse.SetAnimationState(CivvieSprite.AnimationState.Dead); Game1.game.PlayCue("guy_die"); }
public Action TryMoveAround() { debug.Log (showDebug, 24, "TryMoveAround"); core.agent.Stop (); //if ( core.agent.isActiveAndEnabled ) core.agent.enabled = false; current_behavior_state = BehaviorState.TryMoveAround; steering_timer = 0; canTakeBackControlFromManualSteering = false; InvokeRepeating ("ManualSteering", 0f, steering_update_freq); yield return NodeResult.Success; }
public Action MoveAlongPath() { debug.Log (showDebug, 23, "MoveAlongPath"); // if (core.type == UnitType.Melee) // core.agent.avoidancePriority = 4; // if (core.type == UnitType.Ranger) // core.agent.avoidancePriority = 5; // if (!core.agent.isActiveAndEnabled) // core.agent.enabled = true; current_behavior_state = BehaviorState.MoveAlongPath; core.IgnoreCurrentEnemy (); core.ReturnToCurrentNode(); yield return NodeResult.Success; }
public Action WaitInPosition() { debug.Log (showDebug, 25, "WaitInPosition"); current_behavior_state = BehaviorState.WaitInPosition; yield return NodeResult.Success; }