//bool isStrafing = false; //bool canStrafe = false; // Use this for initialization void Start() { //AI Start CurrentAIState = AIMode.StartMovement; canFire = true; CurEShield = MaxEShield; GameObject playerShip = GameObject.Find("PlayerShip"); PlayerShipCtrl = playerShip.GetComponent <ShipPlayerController>(); //ChooseMovement(); //axis = transform.right; //startPos = transform.position; StartCoroutine(Firing()); StartCoroutine(CoastForward()); }
protected override void InitOtherThings() { // 单人模式下,AI 属于玩家 if (!PeGameMgr.IsMulti) { if (energy > 0f) { SetOwner(MainPlayer.Instance.entity); } ResetHost(MainPlayer.Instance.entity.Id); } // 监控敌人 creationSkEntity.onHpReduce += (enemy, value) => { if (enemy is SkAliveEntity && !enemy.Equals(null)) { _attackSelfEntity = enemy as SkAliveEntity; _attackSelfView = enemy.GetComponent <ViewCmpt>(); } }; // 战斗模式 _aiMode = defaultAIMode; _cureValueList = new List <float>(); _cureValueList.Add(0f); }
private void PursuePlayer() { // if (modeTime > pursuitTime) // { // } if (modeTime > pursuitTime) { Mode = AIMode.Aim; //lock in facing facing = Facing.DirectionToFacing(Player.Instance.transform.position - this.transform.position); } else { destination = FindClosestAlignedDistance(this.transform.position, Player.Instance.transform.position, preferredFireDistance); Vector3 movement = destination - this.transform.position; float timedPositioningSpeed = moveSpeed * Time.fixedDeltaTime; if (movement.magnitude < timedPositioningSpeed) { Mode = AIMode.Aim; //lock in facing facing = Facing.DirectionToFacing(Player.Instance.transform.position - this.transform.position); } else { movement = movement.normalized * timedPositioningSpeed; } base.MoveWithSliding(movement); } }
/// <summary> /// 在该模式下,当目标进入NPC视野时,NPC将追击目标,直到杀死目标 /// </summary> void updateAIMode2() { if (Target != null) { if (GameCharacterManager.Instance.contaiinsBody(Target)) { Mode = AIMode.NORMAL; } } if (checkRight(Target) != I.IsFacingRight && checkView(Target) && IgnoreFlip == false) { // 目标与NPC不同向 I.flip(); } // 判断是否开始思考 if (isAIThank()) { // 开始思考 AIThank(2, 3); } else { if (AI_PAUSE) { return; } // 更新状态 UpdateState(); } }
// Use this for initialization protected override void Start() { base.Start(); startPos = endPos = Vector2.zero; currentMode = AIMode.Moving; }
private void Start() { EventManager.instance.events[EVENT_TYPES.COMBAT_START].AddListener(StartCombat); currentAIMode = AIMode.Passive; audioSource = GetComponent <AudioSource>(); player = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>(); agent = this.GetComponent <UnityEngine.AI.NavMeshAgent>(); animator = this.transform.GetChild(0).GetComponent <Animator>(); coverPointManger = FindObjectOfType <CoverPointManager>(); collider = this.transform.GetChild(0).GetComponent <CapsuleCollider>(); animator.SetBool("IsShooting", false); dead = false; initialColliderHeight = collider.height; AllyControl[] targets = FindObjectsOfType <AllyControl>(); foreach (AllyControl ac in targets) { if (ac.Alive) { targetsTransform.Add(ac.transform); } } targetsTransform.Add(player); }
public void Escape(int sec) { this.attacker.StopAttack(); this.ShowHUDText("No~~~", Color.red, 1f); this.escapeTo = Time.time + sec; this.AiMode = AIMode.Escape; }
void DetermineMoveState() { //for moving towards player Vector3 directionToPlayer = PlayerShipCtrl.transform.position - transform.position; Vector3 DirToPlayerNorm = directionToPlayer.normalized; float product = Vector3.Dot(transform.up, DirToPlayerNorm); float angle = Mathf.Acos(product); angle = angle * Mathf.Rad2Deg; if (Input.GetKey(KeyCode.C)) { CurrentMoveState = AIMode.MoveTowards; GetComponent <Renderer>().material.color = Color.green; } else { CurrentMoveState = AIMode.Normal; GetComponent <Renderer>().material.color = Color.red; } }
protected IEnumerator AIAttack() { yield return(new WaitForSeconds(0.03f)); this.Running = false; this.Walk = false; this.attacker.StartAttack(); while (aiEnable) { if (this.target == null) { this.AiMode = AIMode.Random; break; } this.trans.LookAt(this.target); //this.trans.position += this.trans.forward * this.MoveSpeed / 100; if (Vector3.Distance(this.trans.position, this.target.position) > (this.AttackRange + attacker.Level * .5f)) { this.attacker.StopAttack(); this.AiMode = AIMode.Chase; break; } yield return(new WaitForSeconds(0.03f)); } }
public void Act(Hero hero, Map dMap) { //check for hero in sight if (Vector2.Distance(new Vector2(hero.mapX, hero.mapY), new Vector2(mapX, mapY)) < 6 && dMap.LoSLine(mapX, mapY, hero.mapX, hero.mapY)) { curAIMode = AIMode.Aggro; curTarLoc = new Point(hero.mapX, hero.mapY); if (Math.Abs(mapX - hero.mapX) + Math.Abs(mapY - hero.mapY) != 1) { mQueue = dMap.PathTo(new Point(mapX, mapY), curTarLoc, false, false); if (mQueue.Count > 20 || mQueue.Count == 0) { //Console.WriteLine(string.Format("{0} found unusable path (length {1}) - calculating direct path",name,mQueue.Count)); mQueue = dMap.PathTo(new Point(mapX, mapY), curTarLoc, false, true); //Console.WriteLine(string.Format("{0} found direct path (length {1})", name, mQueue.Count)); } } } //act accordingly if (curAIMode == AIMode.Wander) { while (mQueue.Count == 0) { curTarLoc = dMap.openSquares[rando.Next(dMap.openSquares.Count)]; if (dMap.blocks[curTarLoc.X, curTarLoc.Y]) { mQueue = dMap.PathTo(new Point(mapX, mapY), curTarLoc, false); } } MoveFromQueue(dMap); } if (curAIMode == AIMode.Alert) { MoveFromQueue(dMap); if (mQueue.Count == 0) { curAIMode = AIMode.Wander; } } if (curAIMode == AIMode.Aggro) { if (dMap.LoSLine(mapX, mapY, hero.mapX, hero.mapY)) { //Console.WriteLine(string.Format("Moving from {0}, {1} to {2}, {3}", mapX, mapY, mQueue[0].X, mQueue[0].Y)); if (Math.Abs(mapX - hero.mapX) + Math.Abs(mapY - hero.mapY) == 1) { Attack(hero); } else { MoveFromQueue(dMap); } } else { curAIMode = AIMode.Alert; } } }
private void Cooldown() { if (modeTime > postFireCooldown) { Mode = AIMode.Pursue; } }
public DogBrain(Mob parent) { curplan = AIMode.stop; plantime = 0; mob = parent; random = new Random(); }
public override void AIControl(AIMode aiMode) { //if (aiMode == AIMode.) tempTurretTimer += OrbIt.Game.Time.ElapsedGameTime.Milliseconds; if (tempTurretTimer > TurretTimerSeconds * 1000) { float nearest = float.MaxValue; Node nearNode = null; foreach (Node n in room.Groups.Player.entities) { float dist = Vector2R.Distance(parent.body.pos, n.body.pos); if (dist < nearest) { nearNode = n; nearest = dist; } } if (nearNode != null) { Vector2R dir = nearNode.body.pos - parent.body.pos; VMath.NormalizeSafe(ref dir); dir.Y *= -1; FireNode(dir); tempTurretTimer = 0; } } }
// AI State void DetermineAIState() { //For Steering toward player Vector3 directionToPlayer = PlayerShipCtrl.transform.position - transform.position; Vector3 DirToPlayerNorm = directionToPlayer.normalized; float product = Vector3.Dot(transform.up, DirToPlayerNorm); float angle = Mathf.Acos(product); angle = angle * Mathf.Rad2Deg; bool canSee = CanSeeTarget("PlayerShip"); if (startMovement == true) { UpdateStartMovement(); } else if (canSee && product > 0 && angle < 90) { CurrentAIState = AIMode.AimTowards; GetComponent <Renderer>().material.color = Color.green; } if (canSee) { GetComponent <Renderer>().material.color = Color.red; } }
protected IEnumerator AIEscape() { this.ani.Play("Idle"); this.Running = true; this.Walk = false; this.trans.Rotate(Vector3.up, 180); while (aiEnable) { this.trans.position += this.trans.forward * this.MoveSpeed / 100; if (escapeTo < Time.time) { if (this.target) { this.trans.LookAt(this.target); AiMode = AIMode.Chase; } else { AiMode = AIMode.Random; } break; } yield return(new WaitForSeconds(0.03f)); } }
// Update is called once per frame void Update() { if (AI_ON == false) { return; } if (I.CurrentState == StateEnum.HURT) { Mode = AIMode.CRAZY; } switch (Mode) { case AIMode.IDLE: updateAIMode0(); break; case AIMode.NORMAL: updateAIMode1(); break; case AIMode.CRAZY: updateAIMode2(); break; } }
// Update is called once per frame private void Update() { if (isFrozen) { return; } var displacement = GetOffscreenDisplacement(); if (displacement != Vector2.zero) { this.rigidbody2D.position = this.rigidbody2D.position + displacement; // Warp enemy so it can reappear. return; // Continue movement next frame. } if (referenceFrame.player != null) { enemyToPlayerVector = this.transform.position - referenceFrame.player.transform.position; var enemyToPlayerAngle = Mathf.Atan2(enemyToPlayerVector.y, enemyToPlayerVector.x) * Mathf.Rad2Deg - 90; // -90 se saco al ojo. this.rigidbody2D.MoveRotation(enemyToPlayerAngle); } this.velocity = -currentPos; // velocidad(t2) = posicion(t2) - posicion(t1) switch (currentMode) { case AIMode.Moving: if (referenceFrame.player == null) { return; } currentPos -= (Vector2)referenceFrame.player.transform.up * movementSpeed; break; case AIMode.ForcedMovement: if (timeCounter <= 1) { timeCounter += Time.deltaTime * _forcedSpeed; currentPos = Vector2Ex.Hermite(startPos, endPos, timeCounter); } else { currentMode = AIMode.Moving; return; // Restart next frame. } break; default: return; // Do nothing. } this.velocity += currentPos; // velocidad(t2) = posicion(t2) - posicion(t1) this.rigidbody2D.MovePosition(currentPos); }
public PlayerInfo(PlayerID pID, ControlID cID, AIMode _aiMode, PlayerColor pClr) { playerID = pID; controlID = cID; aiMode = _aiMode; playerClr = pClr; }
public override void TouchedByWall(Collider other) { if (Mode != AIMode.Stop) { trigger.enabled = false; Mode = AIMode.Stop; } }
private void Aim() { if (modeTime > aimTime) { Fire(); Mode = AIMode.Cooldown; } }
public override void ForceMovement(Vector2 targetPosition, float forcedSpeed) { timeCounter = 0; currentMode = AIMode.ForcedMovement; startPos = this.rigidbody2D.position; endPos = targetPosition; _forcedSpeed = forcedSpeed; }
void ChangeBattle(AIMode type) { if (RobotController.playerFollower == null) { return; } RobotController.playerFollower.aiMode = type; }
// Use this for initialization protected override void Start() { base.Start(); startPos = endPos = Vector2.zero; currentMode = AIMode.PreAim; UpdateAIVariables(); }
private void StartMove() { Mode = AIMode.Move; //choose direction facing = Facing.RandomFacingThatIsntThisOne(facing); trajectory = Facing.FacingToUnitVector3(facing); //choose length of travel chosenTravelTime = Random.Range(minTravelTime, maxTravelTime); }
// Use this for initialization protected override void Start() { base.Start(); startPos = endPos = Vector2.zero; currentMode = AIMode.Undecided; UpdateAIVariables(); }
public void OnKillDie(Transform target) { this.scanEnemy.RemoveTarget(target); if (this.target == target) { this.AiMode = AIMode.Random; this.SetAttackTarget(null); this.scanEnemy.GetNextTarget(); } }
public void Act(Hero hero, Map dMap) { //check for hero in sight if (Vector2.Distance(new Vector2(hero.mapX, hero.mapY), new Vector2(mapX, mapY)) < 6 && dMap.LoSLine(mapX, mapY, hero.mapX, hero.mapY)) { curAIMode = AIMode.Aggro; curTarLoc = new Point(hero.mapX, hero.mapY); if (Math.Abs(mapX - hero.mapX) + Math.Abs(mapY - hero.mapY) != 1) { mQueue = dMap.PathTo(new Point(mapX, mapY), curTarLoc, false, false); if (mQueue.Count > 20 || mQueue.Count == 0) { //Console.WriteLine(string.Format("{0} found unusable path (length {1}) - calculating direct path",name,mQueue.Count)); mQueue = dMap.PathTo(new Point(mapX, mapY), curTarLoc, false, true); //Console.WriteLine(string.Format("{0} found direct path (length {1})", name, mQueue.Count)); } } } //act accordingly if (curAIMode == AIMode.Wander) { while (mQueue.Count == 0) { curTarLoc = dMap.openSquares[rando.Next(dMap.openSquares.Count)]; if (dMap.blocks[curTarLoc.X, curTarLoc.Y]) { mQueue = dMap.PathTo(new Point(mapX, mapY), curTarLoc, false); } } MoveFromQueue(dMap); } if (curAIMode == AIMode.Alert) { MoveFromQueue(dMap); if (mQueue.Count == 0) curAIMode = AIMode.Wander; } if (curAIMode == AIMode.Aggro) { if (dMap.LoSLine(mapX, mapY, hero.mapX, hero.mapY)) { //Console.WriteLine(string.Format("Moving from {0}, {1} to {2}, {3}", mapX, mapY, mQueue[0].X, mQueue[0].Y)); if (Math.Abs(mapX - hero.mapX) + Math.Abs(mapY - hero.mapY) == 1) { Attack(hero); } else MoveFromQueue(dMap); } else { curAIMode = AIMode.Alert; } } }
static void Reset() { State = GameState.NoGame; Mode = AIMode.Manual; TurnScore = 0; DiceToRoll = 6; Roll = null; ActionsPossible = new List <FarkleAction>(); Players = new LinkedList <FarklePlayer>(); Players.AddLast(new FarklePlayer("MrSmartyPants", PlayerType.AI)); }
public void setPlayerInfoForControlID(ControlID cID, PlayerID pID, AIMode aiMode, PlayerColor pClr) { // if(playerControllerMappings.Where (pcm => pcm.playerID == pID).ToList().Count == 0) // playerControllerMappings.Where (pcm => pcm.controlID == cID).First ().playerID = PlayerID.AI; // else PlayerInfo pInfo = playerInfoList.Where(pcm => pcm.controlID == cID).First(); pInfo.playerID = pID; pInfo.aiMode = aiMode; pInfo.playerClr = pClr; }
public SimObject(Vector2 Position, string name, AIMode action, floor f, Queue <SimEvent> Q) { if (Q != null && SEQ == null) { SEQ = Q; } Name = String.Format("{0}{1}", name, serial); ++serial; position = Position; Action = action; Fl = f; }
public override void ChangeMode(AIMode mode) { Action = mode; if (Fl == floor.first) { Target = SimConsts.points[(int)SimConsts.point.E1f]; } else { Target = SimConsts.points[(int)SimConsts.point.E2f]; } }
// Use this for initialization void Start() { //movestate CurrentMoveState = AIMode.Normal; GetComponent <Collider>().name = subTypeName; //playership component GameObject playerShip = GameObject.Find("PlayerShip"); PlayerShipCtrl = playerShip.GetComponent <ShipPlayerController>(); }
public Monster(string mName, int mtype, int mapx, int mapy) { name = mName; mapX = mapx; mapY = mapy; type = mtype; mQueue = new List<Point>(); delay = 0; curAIMode = 0; curTarLoc = new Point(0, 0); rando = new Random(); alive = true; }
// Update is called once per frame private void Update() { if (isFrozen) return; var displacement = GetOffscreenDisplacement(); if (displacement != Vector2.zero) { this.rigidbody2D.position = this.rigidbody2D.position + displacement; // Warp enemy so it can reappear. return; // Continue movement next frame. } if (referenceFrame.player != null) { enemyToPlayerVector = this.transform.position - referenceFrame.player.transform.position; var enemyToPlayerAngle = Mathf.Atan2(enemyToPlayerVector.y, enemyToPlayerVector.x) * Mathf.Rad2Deg - 90; // -90 se saco al ojo. this.rigidbody2D.MoveRotation(enemyToPlayerAngle); } this.velocity = -currentPos; // velocidad(t2) = posicion(t2) - posicion(t1) switch (currentMode) { case AIMode.Moving: if (referenceFrame.player == null) return; currentPos -= (Vector2)referenceFrame.player.transform.up * movementSpeed; break; case AIMode.ForcedMovement: if (timeCounter <= 1) { timeCounter += Time.deltaTime * _forcedSpeed; currentPos = Vector2Ex.Hermite(startPos, endPos, timeCounter); } else { currentMode = AIMode.Moving; return; // Restart next frame. } break; default: return; // Do nothing. } this.velocity += currentPos; // velocidad(t2) = posicion(t2) - posicion(t1) this.rigidbody2D.MovePosition(currentPos); }
public void BeSoSoAI() { mode = AIMode.SOSO; }
public virtual void AIControl(AIMode aiMode) { }
public void BeTrashAI() { // Rotate for some degree mode = AIMode.TRASH; }
public override void AIControl(AIMode aiMode) { //if (aiMode == AIMode.) tempTurretTimer += OrbIt.gametime.ElapsedGameTime.Milliseconds; if (tempTurretTimer > TurretTimerSeconds * 1000) { float nearest = float.MaxValue; Node nearNode = null; foreach (Node n in room.groups.player.entities) { float dist = Vector2.Distance(parent.body.pos, n.body.pos); if (dist < nearest) { nearNode = n; nearest = dist; } } if (nearNode != null) { Vector2 dir = nearNode.body.pos - parent.body.pos; VMath.NormalizeSafe(ref dir); dir.Y *= -1; FireNode(dir); tempTurretTimer = 0; } } }
// Update is called once per frame private void Update() { if (isFrozen) return; var displacement = GetOffscreenDisplacement(); if (displacement != Vector2.zero) { currentPos += displacement; startPos += displacement; endPos += displacement; this.rigidbody2D.position = currentPos; // Warp enemy so it can reappear. return; // Continue movement next frame. } this.velocity = -currentPos; // velocidad(t2) = posicion(t2) - posicion(t1) switch (currentMode) { case AIMode.PreAim: if (referenceFrame.player != null) { enemyToPlayerVector = this.transform.position - referenceFrame.player.transform.position; var enemyToPlayerAngle = Mathf.Atan2(enemyToPlayerVector.y, enemyToPlayerVector.x) * Mathf.Rad2Deg - 90; // -90 se saco al ojo. startRotation = this.rigidbody2D.rotation; endRotation = enemyToPlayerAngle; timeCounter = 0; currentMode = AIMode.Aiming; } break; case AIMode.Aiming: if (timeCounter <= 1) { currentRotation = Mathf.LerpAngle(startRotation, endRotation, timeCounter); this.rigidbody2D.MoveRotation(currentRotation); timeCounter += Time.deltaTime * _aimingSpeed; } else { timeCounter = 0; currentMode = AIMode.Windup; return; } break; case AIMode.Windup: if (timeCounter >= _windupTime) { timeCounter = 0; currentMode = AIMode.Charge; return; // Start movement on next frame } else { timeCounter += Time.deltaTime; currentPos += (Vector2)this.rigidbody2D.transform.up * _windupSpeed; // El "up" de la nave es hacia 'adelante'. } break; case AIMode.Charge: if (timeCounter >= _chargeTime) { if (IsOffscreen()) { timeCounter -= 1; // Continue movement if it ends while offscreen. } else { currentMode = AIMode.PreAim; return; // Start movement on next frame } } else { timeCounter += Time.deltaTime; var scaler = (_chargeTime - timeCounter) / _chargeTime; currentPos -= (Vector2)this.rigidbody2D.transform.up * _chargeSpeed * scaler; } break; case AIMode.ForcedMovement: if (timeCounter <= 1) { timeCounter += Time.deltaTime * _forcedSpeed; currentPos = Vector2Ex.Hermite(startPos, endPos, timeCounter); } else { currentMode = AIMode.PreAim; return; // Restart next frame. } break; default: return; // Do nothing. } this.velocity += currentPos; // velocidad(t2) = posicion(t2) - posicion(t1) this.rigidbody2D.MovePosition(currentPos); }
protected override IEnumerator FreezeCoroutine(float duration) { yield return StartCoroutine(base.FreezeCoroutine(duration)); currentMode = AIMode.PreAim; }