wip
This commit is contained in:
@@ -58,7 +58,7 @@ public abstract class Character : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
_isOnBridge = downBlock == MapElementType.Bridge && !_isFalling;
|
_isOnBridge = downBlock == MapElementType.Bridge && !_isFalling;
|
||||||
|
GetMapElement(Vector2.up);
|
||||||
if (downBlock == MapElementType.Wall || _isOnLadder || _isOnBridge || downBlock == MapElementType.BreakableWall)
|
if (downBlock == MapElementType.Wall || _isOnLadder || _isOnBridge || downBlock == MapElementType.BreakableWall)
|
||||||
{
|
{
|
||||||
var leftCheck = GetMapElement(Vector2.left);
|
var leftCheck = GetMapElement(Vector2.left);
|
||||||
@@ -130,16 +130,27 @@ public abstract class Character : MonoBehaviour
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private MapElementType GetMapElement(Vector3 direction)
|
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);
|
//var cell = _tileMap.WorldToCell(bounds + direction);
|
||||||
Vector2 cell2d = new Vector2(cell.x + 0.5f, cell.y + 0.3f);
|
//Vector2 cell2d = new Vector2(cell.x + 0.5f, cell.y + 0.3f);
|
||||||
Vector2 cellSize = new Vector2(_cellSize.x - 0.3f, _cellSize.y - 0.05f);
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cellSize = cellSize / 2;
|
|
||||||
var raycastHit = Physics2D.BoxCast(cell2d, cellSize, 0f, Vector3.zero, 0.01f, _mapLayer);
|
|
||||||
MapElementType returnValue;
|
MapElementType returnValue;
|
||||||
Color color = Color.red;
|
Color color = Color.red;
|
||||||
if (raycastHit)
|
if (raycastHit)
|
||||||
@@ -172,12 +183,17 @@ public abstract class Character : MonoBehaviour
|
|||||||
{
|
{
|
||||||
returnValue = MapElementType.Empty;
|
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, 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 + 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, cell2d + new Vector2(0, cellSize.y), color);
|
||||||
Debug.DrawLine(cell2d + new Vector2(0, cellSize.y), cell2d + new Vector2(cellSize.x, 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();
|
protected abstract void OnDeath();
|
||||||
|
|||||||
Reference in New Issue
Block a user