void HideFromPlayer() { if (!isMoving && !IsHidden(transform.position, player.transform.position)) { isMoving = true; grid.FindPath(transform.position, GetNodeToHide().position); } }
void Update() { if (enemy.enemyMode == EnemyFSM.Stopped) { enemy.room = grid.NodeFromWorldPoint(player.transform.position).room; grid.FindPath(enemy.transform.position, player.transform.position); enemy.nextNode = grid.path[0]; enemy.enemyMode = EnemyFSM.ChangingRoom; } }
void MoveEnemy() { if (grid.path.Count > 0) { float dist = Vector3.Distance(transform.position, nextNode.position); if (dist < 0.001f) { nextNode = grid.path[0]; grid.path.RemoveAt(0); } } else { if (Vector3.Distance(transform.position, nextNode.position) < 0.001f) { switch (enemyMode) { case EnemyFSM.ChangingRoom: enemyMode = EnemyFSM.Patrolling; waypoints.AddRange(room.waypoints); break; case EnemyFSM.Patrolling: if (waypoints.Count > 0) { grid.FindPath(transform.position, waypoints[0].position); waypoints.RemoveAt(0); nextNode = grid.path[0]; } else { enemyMode = EnemyFSM.Stopped; } break; } } } float step = speed * Time.deltaTime; // calculate distance to move transform.position = Vector3.MoveTowards(transform.position, nextNode.position, step); }