boundings

This commit is contained in:
2023-07-12 19:43:46 +03:00
parent 03cd45110d
commit 94b9c7cc0c
3 changed files with 167 additions and 27 deletions
+8 -3
View File
@@ -2731,7 +2731,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 86.7561, y: -33.80829}
m_AnchoredPosition: {x: 86.7561, y: -33.80835}
m_SizeDelta: {x: 173.5123, y: 52.6699}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &432019649
@@ -2944,6 +2944,7 @@ MonoBehaviour:
_bonesSide: {fileID: 0}
_bonesBack: {fileID: 0}
_spawnPoint: {fileID: 0}
_tileMap: {fileID: 350695917}
_mapLayer:
serializedVersion: 2
m_Bits: 8
@@ -5649,8 +5650,8 @@ CapsuleCollider2D:
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_Size: {x: 0.8, y: 0.89}
m_Offset: {x: -0.04, y: 0}
m_Size: {x: 0.55, y: 0.89}
m_Direction: 0
--- !u!1 &1744467215
GameObject:
@@ -6609,6 +6610,10 @@ PrefabInstance:
propertyPath: m_Layer
value: 8
objectReference: {fileID: 0}
- target: {fileID: 1693252312754102175, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: _tileMap
value:
objectReference: {fileID: 350695917}
- target: {fileID: 1693252312754102175, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: _bonesBack
value:
+120 -2
View File
@@ -123,6 +123,37 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &17312387
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 17312388}
m_Layer: 0
m_Name: PlayerSpawnPoint
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &17312388
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 17312387}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -5.4586916, y: 2.6285906, z: 0.006108283}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &276473122
GameObject:
m_ObjectHideFlags: 0
@@ -875,7 +906,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalPosition.y
value: -1.5
value: 1.5
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalPosition.z
@@ -945,7 +976,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 965998752200834250, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: m_LocalPosition.y
value: 0.17
value: 2.77
objectReference: {fileID: 0}
- target: {fileID: 965998752200834250, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: m_LocalPosition.z
@@ -991,6 +1022,10 @@ PrefabInstance:
propertyPath: m_Layer
value: 8
objectReference: {fileID: 0}
- target: {fileID: 1693252312754102175, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: _tileMap
value:
objectReference: {fileID: 276473128}
- target: {fileID: 1693252312754102175, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: _bonesBack
value:
@@ -999,6 +1034,10 @@ PrefabInstance:
propertyPath: _bonesSide
value:
objectReference: {fileID: 331482256}
- target: {fileID: 1693252312754102175, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: _spawnPoint
value:
objectReference: {fileID: 17312387}
- target: {fileID: 1716637651858965058, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
propertyPath: m_LinearDrag
value: 1
@@ -1723,6 +1762,7 @@ Transform:
- {fileID: 1022517336}
- {fileID: 678844054}
- {fileID: 2134400060}
- {fileID: 2003579423}
m_Father: {fileID: 617249160}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -1872,6 +1912,79 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
--- !u!1001 &938326545
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 801411103}
m_Modifications:
- target: {fileID: 3364452304498334467, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_UsedByComposite
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6742600071965714980, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_RootOrder
value: -1
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalPosition.x
value: -5.5
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalPosition.y
value: -1.5
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8175732239415438715, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_Name
value: BreakableTile (2)
objectReference: {fileID: 0}
- target: {fileID: 8175732239415438715, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
--- !u!4 &991569139 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
@@ -2312,6 +2425,11 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
--- !u!4 &2003579423 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 7345322822309755345, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
m_PrefabInstance: {fileID: 938326545}
m_PrefabAsset: {fileID: 0}
--- !u!1001 &2043218686
PrefabInstance:
m_ObjectHideFlags: 0
+39 -22
View File
@@ -33,36 +33,39 @@ public abstract class Character : MonoBehaviour
protected bool isAllowVertical = true;
protected bool isAllowRight = true;
protected bool isAllowLeft = true;
private Vector2 _cellSize;
private void Start()
{
_body = GetComponent<Rigidbody2D>();
_capsuleCollider = GetComponent<CapsuleCollider2D>();
_cellSize = new Vector2(_tileMap.cellSize.x, _tileMap.cellSize.y);
}
protected void Spawn()
{
transform.position=_spawnPoint.transform.position;
transform.position = _spawnPoint.transform.position;
}
protected void MoveTo(float inputHorizontal, float inputVertical)
{
var mapElement = GetMapElement(Vector2.down);
var downBlock = GetMapElement(Vector2.down);
if(mapElement==MapElementType.Water)
if (downBlock == MapElementType.Water)
{
Death();
}
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
_isOnBridge = downBlock == MapElementType.Bridge && !_isFalling;
if (mapElement == MapElementType.Wall || _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
if (downBlock == MapElementType.Wall || _isOnLadder || _isOnBridge || downBlock == MapElementType.BreakableWall)
{
var leftCheck = GetMapElement(Vector2.left);
var rightCheck = GetMapElement(Vector2.right);
//print($"LeftCheck:{leftCheck} right:{rightCheck}");
isAllowLeft = !(leftCheck == MapElementType.Wall || leftCheck == MapElementType.BreakableWall);
isAllowRight = !(rightCheck == MapElementType.Wall || rightCheck == MapElementType.BreakableWall);
@@ -76,10 +79,10 @@ public abstract class Character : MonoBehaviour
}
SetWalkingAnimation(h_movement != 0);
;
_isOnLadder = GetMapElement(Vector2.zero) == MapElementType.Ladder || downBlock == MapElementType.Ladder;
_isOnLadder = leftCheck == MapElementType.Ladder && rightCheck == MapElementType.Ladder;
if (leftCheck == MapElementType.Ladder && rightCheck == MapElementType.Ladder)
if (_isOnLadder)
{
float v_movement = inputVertical;
isAllowVertical = true;
@@ -112,7 +115,7 @@ public abstract class Character : MonoBehaviour
_body.velocity = new Vector2(0, _body.velocity.y);
SetWalkingAnimation(false);
if (mapElement == MapElementType.Ladder)
if (downBlock == MapElementType.Ladder)
{
_body.velocity = Vector2.zero;
_isOnLadder = true;
@@ -127,18 +130,16 @@ public abstract class Character : MonoBehaviour
}
private MapElementType GetMapElement(Vector2 direction)
private MapElementType GetMapElement(Vector3 direction)
{
var cell=_tileMap.WorldToCell(transform.position);
var bounds = _facingRight ? _capsuleCollider.bounds.min: _capsuleCollider.bounds.center;
Vector2 rayStartPoint;
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, _capsuleCollider.bounds.min.y + 0.06f);
var boundsSize = new Vector2(_capsuleCollider.bounds.size.x - 0.05f, 0.1f);
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);
var raycastHit = Physics2D.BoxCast(rayStartPoint, boundsSize, 0f, direction, 0.1f, _mapLayer);
cellSize = cellSize / 2;
var raycastHit = Physics2D.BoxCast(cell2d, cellSize, 0f, Vector3.zero, 0.01f, _mapLayer);
MapElementType returnValue;
Color color = Color.red;
if (raycastHit)
@@ -151,15 +152,31 @@ public abstract class Character : MonoBehaviour
}
else
{
color = Color.green;
returnValue = mapElement.ElementSO.ElementType;
switch (returnValue)
{
case MapElementType.Wall:
color = Color.green;
break;
case MapElementType.Ladder:
color = Color.yellow;
break;
case MapElementType.BreakableWall:
color = Color.magenta;
break;
}
}
}
else
{
returnValue = MapElementType.Empty;
}
Debug.DrawRay(rayStartPoint, direction, 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;
}