Improve enemy logic
This commit is contained in:
@@ -38,8 +38,18 @@ public class Character : MonoBehaviour
|
||||
{
|
||||
var leftCheck = CheckBounds(Vector2.left, groundLayer);
|
||||
var rightCheck = CheckBounds(Vector2.right, groundLayer);
|
||||
if(leftCheck) { isAllowLeft = false; }
|
||||
if (rightCheck) { isAllowRight = false; }
|
||||
if(leftCheck.collider!=null) {
|
||||
isAllowLeft = false;
|
||||
}else
|
||||
{
|
||||
isAllowLeft = true;
|
||||
}
|
||||
if (rightCheck.collider != null) {
|
||||
isAllowRight = false;
|
||||
}else
|
||||
{
|
||||
isAllowRight = true;
|
||||
}
|
||||
|
||||
isAllowVertical = false;
|
||||
_isFall = false;
|
||||
|
||||
@@ -8,16 +8,16 @@ public class EnemyAI : Character
|
||||
float horizontal = 0;
|
||||
float vertical = 0;
|
||||
|
||||
if (Player.Instance.transform.position.x - transform.position.x > -0.1f && isAllowLeft)
|
||||
if (Player.Instance.transform.position.x - transform.position.x < -0.05f && isAllowLeft)
|
||||
{
|
||||
horizontal = -1;
|
||||
}
|
||||
else if (Player.Instance.transform.position.x - transform.position.x > 0.1f && isAllowRight)
|
||||
else if (Player.Instance.transform.position.x - transform.position.x > 0.05f && isAllowRight)
|
||||
{
|
||||
horizontal = 1;
|
||||
}
|
||||
|
||||
else if (Mathf.Abs(Player.Instance.transform.position.y - transform.position.y) > 0.1f && isAllowVertical)
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user