starting work on enemy ai
This commit is contained in:
@@ -18,13 +18,15 @@ public class Character : MonoBehaviour
|
||||
private bool _isFall;
|
||||
private bool _facingRight = true;
|
||||
|
||||
|
||||
protected bool isAllowVertical = true;
|
||||
protected bool isAllowHorisontal = true;
|
||||
private void Start()
|
||||
{
|
||||
_body = GetComponent<Rigidbody2D>();
|
||||
_boxCollider = GetComponent<BoxCollider2D>();
|
||||
}
|
||||
|
||||
|
||||
protected void MoveTo(float inputHorizontal,float inputVertical)
|
||||
{
|
||||
var groundCheck = Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, Vector2.down, .1f, groundLayer);
|
||||
@@ -32,6 +34,8 @@ public class Character : MonoBehaviour
|
||||
float v_movement=0;
|
||||
if (groundCheck || _isOnLadder)
|
||||
{
|
||||
isAllowVertical = false;
|
||||
isAllowHorisontal = true;
|
||||
_isFall = false;
|
||||
float h_movement = inputHorizontal;
|
||||
if (h_movement > 0 && !_facingRight)
|
||||
@@ -47,6 +51,7 @@ public class Character : MonoBehaviour
|
||||
|
||||
if (IsLadder(Vector2.down))
|
||||
{
|
||||
isAllowVertical = true;
|
||||
_isOnLadder = true;
|
||||
v_movement=inputVertical;
|
||||
|
||||
|
||||
@@ -3,17 +3,16 @@ using static UnityEditor.Searcher.SearcherWindow.Alignment;
|
||||
|
||||
public class EnemyAI :Character
|
||||
{
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float horizontal = 0;
|
||||
float vertical = 0;
|
||||
if (Mathf.Abs(Player.Instance.transform.position.x - transform.position.x)>0.5f)
|
||||
if (Mathf.Abs(Player.Instance.transform.position.x - transform.position.x)>0.5f && isAllowHorisontal)
|
||||
{
|
||||
horizontal = Player.Instance.transform.position.x - transform.position.x;
|
||||
}
|
||||
else
|
||||
|
||||
if (Mathf.Abs(Player.Instance.transform.position.y - transform.position.y) > 0.5f && isAllowVertical)
|
||||
{
|
||||
vertical = Player.Instance.transform.position.y - transform.position.y;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user