Movement is much better

This commit is contained in:
2023-07-10 18:53:38 +03:00
parent 487372a754
commit 9d68af5244
4 changed files with 387 additions and 120 deletions
+7 -18
View File
@@ -40,8 +40,7 @@ public abstract class Character : MonoBehaviour
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
if (mapElement == MapElementType.Wall)
//|| _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
{
var leftCheck = GetMapElement(Vector2.left);
var rightCheck = GetMapElement(Vector2.right);
@@ -60,29 +59,19 @@ public abstract class Character : MonoBehaviour
SetWalkingAnimation(h_movement != 0);
_isOnLadder =leftCheck == MapElementType.Ladder && rightCheck== MapElementType.Ladder;
_isOnLadder = leftCheck == MapElementType.Ladder && rightCheck == MapElementType.Ladder;
if (leftCheck == MapElementType.Ladder && rightCheck == MapElementType.Ladder)
{
float v_movement = inputVertical;
print($"On ladder v_speed {v_movement}");
isAllowVertical = true;
if (v_movement != 0)
{
//if (v_movement > 0 && mapElement != MapElementType.Ladder)
//{
// v_movement = 0;
//}
SetClimbingAnimation(v_movement != 0);
}
SetClimbingAnimation(v_movement != 0);
_body.velocity = new Vector2(h_movement * MovementSpeed, v_movement * MovementSpeed);
}
else
{
print("On ground");
_body.velocity = new Vector2(h_movement * MovementSpeed, _body.velocity.y);
}
}
@@ -117,13 +106,13 @@ public abstract class Character : MonoBehaviour
private MapElementType GetMapElement(Vector2 direction)
{
Vector2 rayStartPoint;
if (direction==Vector2.down)
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x + direction.x / 2, _capsuleCollider.bounds.min.y -0.1f);
if (direction == Vector2.down)
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x + direction.x / 2, _capsuleCollider.bounds.min.y - 0.1f);
else
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x + direction.x / 2, _capsuleCollider.bounds.min.y+0.1f );
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x, _capsuleCollider.bounds.min.y + 0.05f);
var boundsSize = new Vector2(_capsuleCollider.bounds.size.x - 0.05f, 0.1f);
var raycastHit = Physics2D.BoxCast(rayStartPoint, boundsSize, 0f, direction, 0.9f, _mapLayer);
var raycastHit = Physics2D.BoxCast(rayStartPoint, boundsSize, 0f, direction, 0.1f, _mapLayer);
MapElementType returnValue;
Color color = Color.red;
if (raycastHit)