fix collision system, ladders, and enemy AI
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
|
||||
public class EnemyAI : Character
|
||||
{
|
||||
@@ -18,22 +18,59 @@ public class EnemyAI : Character
|
||||
{
|
||||
float horizontal = 0;
|
||||
float vertical = 0;
|
||||
|
||||
if (Player.Instance.transform.position.x - transform.position.x < -0.05f && isAllowLeft &&!_isOnLadder)
|
||||
|
||||
Vector2 directionToPlayer = Player.Instance.transform.position - transform.position;
|
||||
directionToPlayer.Normalize(); // Нормализуем вектор, чтобы скорость была постоянной
|
||||
|
||||
// Преследуем игрока только по горизонтали, если враг не на лестнице
|
||||
if (!_isOnLadder)
|
||||
{
|
||||
horizontal = -1;
|
||||
horizontal = directionToPlayer.x;
|
||||
}
|
||||
else if (Player.Instance.transform.position.x - transform.position.x > 0.05f && isAllowRight && !_isOnLadder)
|
||||
else
|
||||
{
|
||||
horizontal = 1;
|
||||
// Вычисляем направление движения к игроку по вертикали, если враг на лестнице
|
||||
float verticalDistance = Player.Instance.transform.position.y - transform.position.y;
|
||||
float verticalDirection = Mathf.Sign(verticalDistance);
|
||||
vertical = verticalDirection;
|
||||
}
|
||||
|
||||
else if (Mathf.Abs(Player.Instance.transform.position.y - transform.position.y) > 0.05f && isAllowVertical)
|
||||
if (!isAllowVertical)
|
||||
{
|
||||
var deltaY = Player.Instance.transform.position.y - transform.position.y;
|
||||
vertical = deltaY > 0 ? 1 : -1;
|
||||
float verticalDistance = Player.Instance.transform.position.y - transform.position.y;
|
||||
float verticalDirection = Mathf.Sign(verticalDistance);
|
||||
vertical = verticalDirection;
|
||||
}
|
||||
|
||||
|
||||
float horizontalDistance = Player.Instance.transform.position.x - transform.position.x;
|
||||
float horizontalDirection = Mathf.Sign(horizontalDistance);
|
||||
horizontal = horizontalDirection;
|
||||
|
||||
|
||||
|
||||
//if (Player.Instance.transform.position.x - transform.position.x < -0.05f && isAllowLeft &&!_isOnLadder)
|
||||
//{
|
||||
// horizontal = -1;
|
||||
//}
|
||||
//else if (Player.Instance.transform.position.x - transform.position.x > 0.05f && isAllowRight && !_isOnLadder)
|
||||
//{
|
||||
// horizontal = 1;
|
||||
//}
|
||||
|
||||
//else if (Mathf.Abs(Player.Instance.transform.position.y - transform.position.y) > 0.05f && isAllowVertical)
|
||||
//{
|
||||
// var deltaY = Player.Instance.transform.position.y - transform.position.y;
|
||||
// vertical = deltaY > 0 ? 1 : -1;
|
||||
//}
|
||||
if (Input.GetKey(KeyCode.F))
|
||||
{ horizontal = -1; }
|
||||
if (Input.GetKey(KeyCode.H))
|
||||
{ horizontal = 1; }
|
||||
if (Input.GetKey(KeyCode.T))
|
||||
{ vertical = 1; }
|
||||
if (Input.GetKey(KeyCode.G))
|
||||
{ vertical = -1; }
|
||||
base.MoveTo(horizontal, vertical);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user