Fixed movement rules
This commit is contained in:
@@ -26,7 +26,7 @@ public abstract class Character : MonoBehaviour
|
||||
protected bool _isFalling;
|
||||
protected bool _facingRight = true;
|
||||
|
||||
|
||||
protected bool isCanClimbUp=false;
|
||||
protected bool isAllowVertical = true;
|
||||
protected bool isAllowRight = true;
|
||||
protected bool isAllowLeft = true;
|
||||
@@ -73,17 +73,25 @@ public abstract class Character : MonoBehaviour
|
||||
|
||||
if (_isOnLadder)
|
||||
{
|
||||
isCanClimbUp=CanClimbUp();
|
||||
|
||||
float ladderXCenterDistance = Mathf.Abs(transform.position.x - block.transform.position.x);
|
||||
|
||||
float v_movement = inputVertical;
|
||||
|
||||
isAllowVertical = (ladderXCenterDistance < 0.3f);
|
||||
if(!isCanClimbUp&& v_movement>0)
|
||||
{
|
||||
v_movement=0;
|
||||
}
|
||||
|
||||
isAllowVertical = (ladderXCenterDistance < 0.3f) || (CanClimbUp() && v_movement>0);
|
||||
if (isAllowVertical)
|
||||
{
|
||||
SetClimbingAnimation(v_movement != 0);
|
||||
_body.velocity = new Vector2(h_movement * _movementSpeed, v_movement * _movementSpeed);
|
||||
}
|
||||
else{
|
||||
_body.velocity = new Vector2(h_movement * _movementSpeed, _body.velocity.y);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -20,18 +20,22 @@ public class EnemyAI : Character
|
||||
float horizontal = 0;
|
||||
float vertical = 0;
|
||||
|
||||
Vector2 directionToPlayer = Player.Instance.transform.position - transform.position;
|
||||
Vector2 directionToPlayer = Player.Instance.transform.position - transform.position;
|
||||
directionToPlayer.Normalize();
|
||||
|
||||
float verticalDistance = Player.Instance.transform.position.y - transform.position.y;
|
||||
|
||||
if (Mathf.Abs(Player.Instance.transform.position.y - transform.position.y) < 0.1f)
|
||||
{
|
||||
horizontal = directionToPlayer.x;
|
||||
}
|
||||
else if (isAllowVertical)
|
||||
else if (verticalDistance>0 && isCanClimbUp && isAllowVertical)
|
||||
{
|
||||
float verticalDistance = Player.Instance.transform.position.y - transform.position.y;
|
||||
float verticalDirection = Mathf.Sign(verticalDistance);
|
||||
vertical = verticalDirection;
|
||||
vertical =VerticalMove(verticalDistance);
|
||||
}
|
||||
else if (verticalDistance<0 && isAllowVertical)
|
||||
{
|
||||
vertical =VerticalMove(verticalDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -48,4 +52,10 @@ public class EnemyAI : Character
|
||||
{ vertical = -1; }
|
||||
base.MoveTo(horizontal, vertical);
|
||||
}
|
||||
|
||||
private float VerticalMove(float verticalDistance)
|
||||
{
|
||||
float verticalDirection = Mathf.Sign(verticalDistance);
|
||||
return verticalDirection;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user