This commit is contained in:
2023-07-13 06:19:44 +03:00
parent 94b9c7cc0c
commit eb9e4beaf7
+25 -9
View File
@@ -58,7 +58,7 @@ public abstract class Character : MonoBehaviour
}
_isOnBridge = downBlock == MapElementType.Bridge && !_isFalling;
GetMapElement(Vector2.up);
if (downBlock == MapElementType.Wall || _isOnLadder || _isOnBridge || downBlock == MapElementType.BreakableWall)
{
var leftCheck = GetMapElement(Vector2.left);
@@ -130,16 +130,27 @@ public abstract class Character : MonoBehaviour
}
private MapElementType GetMapElement(Vector3 direction)
{
var bounds = _facingRight ? _capsuleCollider.bounds.min: _capsuleCollider.bounds.center;
var bounds = _capsuleCollider.bounds.min;
//var cell = _tileMap.WorldToCell(bounds + direction);
//Vector2 cell2d = new Vector2(cell.x + 0.5f, cell.y + 0.3f);
Vector2 cellSize = new Vector2(0.9f,0.8f);
var playerBounds = _capsuleCollider.bounds.min;
playerBounds += new Vector3(0.01f, 0.01f);
DrawBounds(playerBounds, cellSize, Color.cyan);
playerBounds = playerBounds + direction;
var raycastHit = Physics2D.BoxCast(playerBounds, cellSize, 0f, Vector3.forward, .01f, _mapLayer);
var cell = _tileMap.WorldToCell(bounds + direction);
Vector2 cell2d = new Vector2(cell.x + 0.5f, cell.y + 0.3f);
Vector2 cellSize = new Vector2(_cellSize.x - 0.3f, _cellSize.y - 0.05f);
cellSize = cellSize / 2;
var raycastHit = Physics2D.BoxCast(cell2d, cellSize, 0f, Vector3.zero, 0.01f, _mapLayer);
MapElementType returnValue;
Color color = Color.red;
if (raycastHit)
@@ -172,12 +183,17 @@ public abstract class Character : MonoBehaviour
{
returnValue = MapElementType.Empty;
}
DrawBounds(playerBounds, cellSize, color);
return returnValue;
}
private static void DrawBounds(Vector2 cell2d, Vector2 cellSize, Color color)
{
Debug.DrawLine(cell2d, cell2d + new Vector2(cellSize.x, 0), color);
Debug.DrawLine(cell2d + new Vector2(cellSize.x, 0), cell2d + new Vector2(cellSize.x, cellSize.y), color);
Debug.DrawLine(cell2d, cell2d + new Vector2(0, cellSize.y), color);
Debug.DrawLine(cell2d + new Vector2(0, cellSize.y), cell2d + new Vector2(cellSize.x, cellSize.y), color);
return returnValue;
}
protected abstract void OnDeath();