public Move ( Vector3 velocity, float force = 1 ) : void | ||
velocity | Vector3 | |
force | float | |
리턴 | void |
public override void Update(Enemy e) { Transform currentPos = e.GetComponent <Transform>(); Vector2 target = e.VectorToPlayer(); Vector2 start = new Vector2(currentPos.position.x, currentPos.position.y); Vector2 dirrection = target - start; float xDistance = dirrection.x; xDistance = Mathf.Abs(xDistance); if (xDistance < e.seekThreshold) { e.ChangeState(new AttackState()); } else { if (dirrection.x < 0) { e.Move(-e.force); } else { e.Move(e.force); } } }
/* * Goes through a monster list and moves them in order. * */ void MonsterMove() { if (monstersToMove.Count == 0) { GiveTurn(); return; } bool move = false; while (!move && monstersToMove.Count > 0) { Enemy monster = monstersToMove[0]; Cell nextCell = monster.Cell.enemyPath; while (nextCell != null && nextCell.Inventory.Enemies.Count > 0 && !Castle.IsCastle(nextCell)) { nextCell = nextCell.enemyPath; } if (nextCell != null) { monster.Move(nextCell); move = true; } else { monstersToMove.Remove(monster); } } }
void Patrol() { var curWay = enemy.waypoints[enemy.currentWaypoint]; // once enemy reaches waypoint, pause for patrolTurnTime seconds before turning around if (Mathf.Abs(curWay.x - enemy.transform.position.x) < closeEnoughThreshold) { enemy.DoNothing(); timer += Time.deltaTime; if (timer > patrolTurnTime) { enemy.currentWaypoint = enemy.currentWaypoint == 1 ? 0 : 1; timer = 0f; } } else { // switch waypoints if run into wall or reach end of platform if (!enemy.CheckForGround()) { enemy.currentWaypoint = enemy.currentWaypoint == 1 ? 0 : 1; } // move toward waypoint var diff = Mathf.Sign(enemy.waypoints[enemy.currentWaypoint].x - enemy.transform.position.x); enemy.Move(diff); } }
void EnemyDied(Enemy character) { character.Target = null; character.Move(transform.position); GetComponent <CapsuleCollider>().enabled = false; Destroy(gameObject, 3f); }
IEnumerator SpawnWave() { //TESTING int remaining = waves[currentWave].enemiesNumber; //:: Every wave choses one random direction //int randomDirection = GetRandomOpenSpawnDirection(); //if (randomDirection == -1) // Debug.LogError("there are no open spawn directions"); while (remaining > 0) { //OR: Every enemy chose random direction int randomDirection = GetRandomOpenSpawnDirection(); if (randomDirection == -1) { Debug.LogError("there are no open spawn directions"); } HexTile spawnTile = spawners[randomDirection].GetRandomOpenTile(); int count = waves[currentWave].enemies.Count; Enemy enemy = Instantiate(waves[currentWave].enemies[Random.Range(0, count)]).GetComponent <Enemy>(); enemy.transform.parent = this.transform; remaining--; //yield return new WaitForSeconds(1f); //Idle for a second enemy.Move(spawnTile); yield return(new WaitForSeconds(waves[currentWave].timeBetweenEnemies)); } }
public void Execute() { Debug.Log("Patroling"); Patrol(); enemy.Move(); }
private void Update() { if (playerMove) { player.Move(move); } if (npcMove) { enemy1.Move(NPCmove); enemy2.Move(NPCmove); } if (moveCamera) { Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, movePos, Time.deltaTime); } }
public override void Update(Enemy enemy) { if (target == null) //目标玩家在锁定后死亡 { //切换到站立状态 enemy.SetState(Enemy.AIState.Idle); //结束 return; } if (enemy.IsInTransforming()) { return; } moveTime += Time.deltaTime; if (moveTime < moveTimeMax && enemy.WalkingCondition(target)) { enemy.Move(dir); enemy.Rotate(dir); } else { //切换到站立状态 enemy.SetState(Enemy.AIState.Idle); } }
public IEnumerator StartQuickReflexesMove() { // TO DO: prevent quick reflex movements from occuring on a characters own turn (only triggered during the enemies turn) TileScript destinationTile = null; List <TileScript> availableTiles = LevelManager.Instance.GetValidMoveableTilesWithinRange(currentMobility, TileCurrentlyOn); destinationTile = availableTiles[Random.Range(0, availableTiles.Count)]; if (destination != null) { if (enemy) { enemy.SetPath(AStar.GetPath(TileCurrentlyOn.GridPosition, destinationTile.GridPosition)); StartCoroutine(enemy.Move(currentMobility, 3)); } else if (defender) { MovementLogic.Instance.MoveEntity(defender, destinationTile); } } yield return(null); }
// void Spawn(){ // GameObject enemy = Instantiate(EnemyPrefab); // Enemy ee = enemy.GetComponent<Enemy>(); // ee.Move(); // } void Spawn1() { GameObject enemy = Instantiate(EnemyPrefab1); Enemy ee = enemy.GetComponent <Enemy1>(); ee.Move(); }
private void PopulateAgents() { for (int x = 0, width = levelData.GetLength(0); x < width; x++) { for (int y = 0, height = levelData.GetLength(1); y < height; y++) { LevelFeatureValue val = levelData[x, y]; if (LevelFeature.HasAgent(val)) { ushort agentId = LevelFeature.GetAgentId(val); Debug.Log($"Agent {agentId} on {x} {y} of type {LevelFeature.GetAgentType(val)}"); switch (LevelFeature.GetAgentType(val)) { case AgentType.PLAYER: PlayerController player = GetPlayer(agentId, x, y); player.Move(GetPositionAt(x, y)); break; case AgentType.MONSTER: Enemy enemy = Beastiary.Instance.GetABeast(currentLevel); SetMovable(agentId, new Movable(x, y, AgentType.MONSTER, enemy.gameObject), true); enemy.Setup(AgentType.MONSTER, agentId); enemy.Move(GetPositionAt(x, y)); break; } } } } Debug.Log($"{movables.Count} movables in level"); }
private void InstantiateEnemy() { // Instantiate random enemy type int randEnemy = GetEnemyType(); Instantiate(Resources.Load("Prefabs/Enemies/" + GetEnemyName(randEnemy)), new Vector3(360, 184, -8), Quaternion.identity); GameObject enemyInstance = GameObject.FindGameObjectWithTag("Enemy"); enemy = enemyInstance.GetComponent <Enemy>(); // Randomly scale enemy int randScale = Random.Range(8, 13); enemyInstance.transform.localScale = new Vector3(randScale / 10f, randScale / 10f, randScale / 10f); // Apply the appropriate rank for the enemy (sprite and stats) int randRank = GetEnemyRank(); enemyInstance.GetComponent <Animator>().SetInteger("Slime Rank", randRank); enemy.ApplyStats(randRank); // Move newly spawned enemy towards the player enemy.Move(new Vector3(105, 184, -8), 2); }
void Attack() { attackForce.transform.parent = null; Enemy enemy = (Enemy)attackForce.GetComponent(typeof(Enemy)); enemy.Move(); }
public void Control() { var player = _room.Players[0]; if (_enemy.IsWaiting) { return; } var distance = new Vector2(player.X - _enemy.X, player.Y - _enemy.Y).Length; var direction = new Vector2(player.X - _enemy.X, player.Y - _enemy.Y); if (direction.X < 0) { _enemy.TurnLeft(); } if (direction.X > 0) { _enemy.TurnRight(); } if (distance > 0.8f * _enemy.ShotRange) { if (_enemy.CanMove(direction, _room)) { _enemy.Move(direction); } } else { direction = new Vector2(player.X - _enemy.XAttack, player.YAttack - _enemy.Y); _enemy.Shoot(_room, new Shot(_enemy.XAttack, _enemy.YAttack, direction, _enemy)); } }
private void LateUpdate() { if (animator.GetCurrentAnimatorStateInfo(0).IsName("Car_Idle") && isPreparing) { isPreparing = false; move = true; } if (move) { //do move enemy.Move(moveDirection, speed); Vector3 cameraRightPosition = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, Camera.main.nearClipPlane)); Vector3 cameraLeftPosition = Camera.main.ScreenToWorldPoint(new Vector3(0, Camera.main.pixelHeight, Camera.main.nearClipPlane)); if (transform.position.x <= cameraLeftPosition.x + edgeOffset && moveDirection == -1) { move = false; } if (transform.position.x >= cameraRightPosition.x - edgeOffset && moveDirection == 1) { move = false; } } }
// Update is called once per frame void Update() { if (isClient) { enemy.Move(); } }
public void MoveTest_OverBorder() { // GameItem-Liste initialisieren GameItem.GameItemList = new System.Collections.Generic.LinkedList <IGameItem>(); // Neuen Gegner erstellen Enemy target = CreateEnemy(); // Gegner an den Rand der Spielebene setzen target.Position = new Vector2(CoordinateConstants.RightBorder, 0.0f); // Passende Parameter initialisieren Vector2 direction = CoordinateConstants.Right; GameTime gameTime = new GameTime(new TimeSpan(0, 42, 42), new TimeSpan(166667)); bool expected = false; // false erwartet, da Alien über Rand geht bool actual; actual = target.Move(direction, gameTime); Assert.AreEqual(expected, actual); // GameItem-Liste zurücksetzen GameItem.GameItemList = null; }
//Runs while in the current State public void Execute() { //If the enemy finds a target while patroling if (thisEnemy.Target == null) { //If he lost his target then go back to patroling thisEnemy.ChangeState(new PatrolState()); } else { //if he is in range for projectile attack then go into ranged state if (thisEnemy.InProjectileRange) { thisEnemy.ChangeState(new RangedState()); } //if he is in melee range then go into MeleeState else if (thisEnemy.InMeleeRange) { thisEnemy.ChangeState(new MeleeState()); } else { //Wait for chase delay before chasing if (chaseDelay < Time.time) { thisEnemy.Move(); } else { thisEnemy.StopMoving(); } } } }
public void EnemyTurn() { if (enemy != null) { darkToasto.Move(); } }
/// <summary> /// Spawns a random enemy /// </summary> /// <returns></returns> public void SpawnEnemy(bool isBoss) { Enemy newEnemy = null; if (!isBoss) { newEnemy = EnemyPools[UnityEngine.Random.Range(0, EnemyPools.Count)].GetFromPool().GenericObj as Enemy; if (m_WaveCounter > 5) { newEnemy.SetMaxHealth((int)(20 + ((m_WaveCounter - 5) * (3 + m_WaveCounter / 20)) + (((m_WaveCounter - 5) * (m_WaveCounter - 5)) / 30))); } } else { newEnemy = BossPools[UnityEngine.Random.Range(0, BossPools.Count)].GetFromPool().GenericObj as Enemy; if (m_WaveCounter > 5) { newEnemy.SetMaxHealth((int)(40 + ((m_WaveCounter - 5) * (8 + m_WaveCounter / 20)) + (((m_WaveCounter - 5) * (m_WaveCounter - 5)) / 15))); } } newEnemy.RestoreHealth(); newEnemy.IsAlive = true; newEnemy.SkeletonAnims.AnimationState.SetAnimation(0, newEnemy.EnemyString + "MOVE", true); SpawnedEnemies.Add(newEnemy); newEnemy.transform.position = MapLoader.s_Instance.Path[0].transform.position; EffectsManager.s_Instance.SpawnEffect(EffectType.ENEMY_SPAWN, false, MapLoader.s_Instance.Path[0].transform.position); newEnemy.Move(MapLoader.s_Instance.Path[0].transform.position); }
public void MoveEnemy() { foreach (Enemy Enemy in Enemies) { Enemy.Move(mainCharacter); } }
public void ExecuteFixed() { if (e.PatrolPoints.Length > 1 && !rotating) { e.Move(new Vector2(e.pathDir.x, e.pathDir.y)); e.LookAt(e._path); } }
// Use this for initialization void Start() { enemy1.Move(); enemy2.Attack(); friendly1.Move(); friendly2.Attack(); }
public void SpawnEntity(string name, int x, int y) { Enemy entity = Entity.Resolve(_world.Manager, name) as Enemy; entity.Move(x, y); _world.EnterWorld(entity); }
IEnumerator FollowPath() { //Debug.Log("Iniciou Nova Paradinha"); bool following = true; int pathindex = 0; while (main_script.Use_Path && following) { // Checa se pode mover if (!main_script.CanMove) { yield break; } if (path.turnBoundaries.Length != 0) { if (path.turnBoundaries.Length > pathindex) { while (path.turnBoundaries[pathindex].HasCrossedLine(transform.position) && main_script.CanMove) { if (pathindex == path.finishLineIndex) { following = false; break; } else { pathindex++; } } } } if (following && main_script.Use_Path) { if (pathindex >= path.lookPoints.Length) { yield break; } else { Vector2 dir = (path.lookPoints[pathindex] - (Vector2)transform.position).normalized; //yield return new WaitForSeconds(1.0f); //Debug.Log("Moving..."); //transform.position = path.lookPoints[pathindex]; main_script.Move(dir); //transform.Translate(dir * Time.deltaTime); } } yield return(new WaitForFixedUpdate()); } }
public void OneMeetOther() { var game = new Game(new Size(2, 2), new Point(0, 0), 2, 1e-9, 1e-9); var enemy = new Enemy(new Point(0, 2), game, new VectorMove(new Vector(0, 2), 1, Vector.Up), 2, 1); game.Player.Move(Direction.Down); enemy.Move(); Assert.True(game.CharactersCollided(game.Player, enemy, 1e-9)); }
// Update is called once per frame void Update() { if (this.flashWait > 0) { this.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 1f); this.flashWait--; } else { this.GetComponent <SpriteRenderer>().color = new Color(0.5f, 0.5f, 0.5f, 1f); } // TODO 突撃はアニメーションで動かしたい enemy.Move(this.gameObject); if (enemy.IsDestroy()) { /* * GameObject explosionObject = new GameObject(); * explosionObject = (GameObject)Object.Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Explosion_sml"), this.gameObject.transform.position, Quaternion.identity); */ GameObject explosionObject; if (this.gameObject.name.StartsWith("Enemy_03_yousai")) { explosionObject = Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Explosion_big 1")); soundManager.PlayAudioClip(SoundManager.AudioClipType.FORT_EXPLOSION); } else { explosionObject = Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Explosion_sml")); GameObject explosionParObject; Animator explosionParAnimator; for (int i = 0; i < 3; i++) { explosionParObject = Instantiate((GameObject)Resources.Load("Scenes/Game/Prefabs/Explosion_par")); explosionParObject.gameObject.transform.position = new Vector3(this.gameObject.transform.position.x + Random.Range(-0.8f, 0.8f), this.gameObject.transform.position.y + Random.Range(-0.8f, 0.8f), this.gameObject.transform.position.z); explosionParObject.gameObject.transform.localScale = new Vector3(Random.Range(1, 3), Random.Range(1, 3)); explosionParAnimator = explosionParObject.GetComponent <Animator>(); explosionParAnimator.Play("efc_exp_par", 0, 0.7f); } SoundManager.AudioClipType explosion; if (Random.Range(0, 2) == 0) { explosion = SoundManager.AudioClipType.EXPLOSION1; } else { explosion = SoundManager.AudioClipType.EXPLOSION2; } soundManager.PlayAudioClip(explosion); } explosionObject.gameObject.transform.position = this.gameObject.transform.position; enemy.ScoreUp(); Destroy(this.gameObject); GameStatus.GetInstance().EnemyKillCount += 1; } }
public void Execute() { Patrol(); enemy.Move(); if (enemy.Target != null) { enemy.ChangeState(new RangeState()); } }
public void Execute() { Patrol(); enemy.Move(); if (enemy.Target != null && enemy.InMeleeRange) { enemy.ChangeState(new MeleeState()); } }
public void Execute(){ //Debug.Log ("I am patrol state"); Patrol (); enemy.Move (); if (enemy.target != null) enemy.ChangeState (new RangedState ()); }
// Use this for initialization void Start() { enemy = GetComponent<Enemy>(); enemy.Move(Vector3.right * 0.1f); }