Fixed movement rules

This commit is contained in:
2023-07-26 15:52:50 +00:00
parent b51381c1ac
commit e65c923810
5 changed files with 41 additions and 23 deletions
+11 -3
View File
@@ -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
{