This commit is contained in:
Vova
2023-07-01 11:08:57 +03:00
parent 4c1443787d
commit f674d0be26
3 changed files with 51 additions and 47 deletions
+47 -46
View File
@@ -37,55 +37,56 @@ public abstract class Character : MonoBehaviour
protected void MoveTo(float inputHorizontal, float inputVertical)
{
var mapElement = GetMapElement(Vector2.down);
var mapElement = GetMapElement(Vector2.down);
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
{
var leftCheck = GetMapElement(Vector2.left);
var rightCheck = GetMapElement(Vector2.right);
isAllowLeft = !(leftCheck == MapElementType.Wall || leftCheck == MapElementType.BreakableWall);
isAllowRight = !(rightCheck == MapElementType.Wall || rightCheck == MapElementType.BreakableWall);
isAllowVertical = false;
_isFalling = false;
float h_movement =inputHorizontal;
if (h_movement > 0 && !_facingRight || h_movement < 0 && _facingRight)
{
FlipCharacter();
}
SetWalkingAnimation(h_movement != 0);
var upperElement = GetMapElement(Vector2.up);
_isOnLadder = mapElement == MapElementType.Ladder || upperElement == MapElementType.Ladder;
if (_isOnLadder)
{
isAllowVertical = true;
_isOnLadder = true;
float v_movement = inputVertical;
if (v_movement > 0 && upperElement != MapElementType.Ladder)
if (mapElement == MapElementType.Wall || _isOnLadder
|| _isOnBridge || mapElement == MapElementType.BreakableWall)
{
v_movement = 0;
}
var leftCheck = GetMapElement(Vector2.left);
var rightCheck = GetMapElement(Vector2.right);
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
{
_isFalling = true;
}
isAllowLeft = !(leftCheck == MapElementType.Wall || leftCheck == MapElementType.BreakableWall);
isAllowRight = !(rightCheck == MapElementType.Wall || rightCheck == MapElementType.BreakableWall);
isAllowVertical = false;
_isFalling = false;
float h_movement = inputHorizontal;
if (h_movement > 0 && !_facingRight || h_movement < 0 && _facingRight)
{
FlipCharacter();
}
SetWalkingAnimation(h_movement != 0);
var upperElement = GetMapElement(Vector2.up);
_isOnLadder = mapElement == MapElementType.Ladder || upperElement == MapElementType.Ladder;
if (_isOnLadder)
{
isAllowVertical = true;
_isOnLadder = true;
float v_movement = inputVertical;
if (v_movement > 0 && upperElement != MapElementType.Ladder)
{
v_movement = 0;
}
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
{
_isFalling = true;
}
}
@@ -95,7 +96,7 @@ else
if (raycastHit)
{
var mapElement = raycastHit.transform.GetComponent<MapElement>();
if (mapElement == null)
if (mapElement == null || !mapElement.IsEnabled)
{
return MapElementType.Empty;
}