character collider issues - WIP
This commit is contained in:
@@ -188,7 +188,7 @@ AnimatorStateMachine:
|
|||||||
m_Position: {x: 170, y: 70, z: 0}
|
m_Position: {x: 170, y: 70, z: 0}
|
||||||
- serializedVersion: 1
|
- serializedVersion: 1
|
||||||
m_State: {fileID: -7806160175022390470}
|
m_State: {fileID: -7806160175022390470}
|
||||||
m_Position: {x: 140, y: 330, z: 0}
|
m_Position: {x: -20, y: 320, z: 0}
|
||||||
- serializedVersion: 1
|
- serializedVersion: 1
|
||||||
m_State: {fileID: -8721553355552428637}
|
m_State: {fileID: -8721553355552428637}
|
||||||
m_Position: {x: 490, y: 220, z: 0}
|
m_Position: {x: 490, y: 220, z: 0}
|
||||||
@@ -355,10 +355,10 @@ AnimatorStateTransition:
|
|||||||
m_Mute: 0
|
m_Mute: 0
|
||||||
m_IsExit: 0
|
m_IsExit: 0
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_TransitionDuration: 0.25
|
m_TransitionDuration: 0
|
||||||
m_TransitionOffset: 0
|
m_TransitionOffset: 0
|
||||||
m_ExitTime: 0.75
|
m_ExitTime: 0.000000001595634
|
||||||
m_HasExitTime: 0
|
m_HasExitTime: 1
|
||||||
m_HasFixedDuration: 1
|
m_HasFixedDuration: 1
|
||||||
m_InterruptionSource: 0
|
m_InterruptionSource: 0
|
||||||
m_OrderedInterruption: 1
|
m_OrderedInterruption: 1
|
||||||
@@ -377,10 +377,10 @@ AnimatorStateTransition:
|
|||||||
m_Mute: 0
|
m_Mute: 0
|
||||||
m_IsExit: 0
|
m_IsExit: 0
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_TransitionDuration: 0.25
|
m_TransitionDuration: 0
|
||||||
m_TransitionOffset: 0
|
m_TransitionOffset: 0
|
||||||
m_ExitTime: 0.75
|
m_ExitTime: 0.0000000065884236
|
||||||
m_HasExitTime: 0
|
m_HasExitTime: 1
|
||||||
m_HasFixedDuration: 1
|
m_HasFixedDuration: 1
|
||||||
m_InterruptionSource: 0
|
m_InterruptionSource: 0
|
||||||
m_OrderedInterruption: 1
|
m_OrderedInterruption: 1
|
||||||
@@ -429,10 +429,10 @@ AnimatorStateTransition:
|
|||||||
m_Mute: 0
|
m_Mute: 0
|
||||||
m_IsExit: 0
|
m_IsExit: 0
|
||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_TransitionDuration: 0.25
|
m_TransitionDuration: 0
|
||||||
m_TransitionOffset: 0
|
m_TransitionOffset: 0
|
||||||
m_ExitTime: 0.75
|
m_ExitTime: 0.0000000030368514
|
||||||
m_HasExitTime: 0
|
m_HasExitTime: 1
|
||||||
m_HasFixedDuration: 1
|
m_HasFixedDuration: 1
|
||||||
m_InterruptionSource: 0
|
m_InterruptionSource: 0
|
||||||
m_OrderedInterruption: 1
|
m_OrderedInterruption: 1
|
||||||
|
|||||||
@@ -5366,8 +5366,8 @@ CapsuleCollider2D:
|
|||||||
m_IsTrigger: 0
|
m_IsTrigger: 0
|
||||||
m_UsedByEffector: 0
|
m_UsedByEffector: 0
|
||||||
m_UsedByComposite: 0
|
m_UsedByComposite: 0
|
||||||
m_Offset: {x: -0.17, y: 0.03}
|
m_Offset: {x: 0, y: 0}
|
||||||
m_Size: {x: 0.6, y: 0.89}
|
m_Size: {x: 0.8, y: 0.89}
|
||||||
m_Direction: 0
|
m_Direction: 0
|
||||||
--- !u!1 &1744467215
|
--- !u!1 &1744467215
|
||||||
GameObject:
|
GameObject:
|
||||||
|
|||||||
@@ -945,7 +945,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 965998752200834250, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
|
- target: {fileID: 965998752200834250, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
|
||||||
propertyPath: m_LocalPosition.y
|
propertyPath: m_LocalPosition.y
|
||||||
value: 1.16
|
value: 0.17
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 965998752200834250, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
|
- target: {fileID: 965998752200834250, guid: a7f273d812293e54d92972f62e1f0159, type: 3}
|
||||||
propertyPath: m_LocalPosition.z
|
propertyPath: m_LocalPosition.z
|
||||||
@@ -1944,83 +1944,6 @@ PrefabInstance:
|
|||||||
m_AddedGameObjects: []
|
m_AddedGameObjects: []
|
||||||
m_AddedComponents: []
|
m_AddedComponents: []
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 3d1aa56cd139405448c73b1385177b04, type: 3}
|
||||||
--- !u!1 &1986976692
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 1986976694}
|
|
||||||
- component: {fileID: 1986976693}
|
|
||||||
m_Layer: 3
|
|
||||||
m_Name: GameObject (1)
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 1
|
|
||||||
--- !u!61 &1986976693
|
|
||||||
BoxCollider2D:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1986976692}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_Density: 1
|
|
||||||
m_Material: {fileID: 0}
|
|
||||||
m_IncludeLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 0
|
|
||||||
m_ExcludeLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 0
|
|
||||||
m_LayerOverridePriority: 0
|
|
||||||
m_ForceSendLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 4294967295
|
|
||||||
m_ForceReceiveLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 4294967295
|
|
||||||
m_ContactCaptureLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 4294967295
|
|
||||||
m_CallbackLayers:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 4294967295
|
|
||||||
m_IsTrigger: 0
|
|
||||||
m_UsedByEffector: 0
|
|
||||||
m_UsedByComposite: 0
|
|
||||||
m_Offset: {x: 0, y: 0}
|
|
||||||
m_SpriteTilingProperty:
|
|
||||||
border: {x: 0, y: 0, z: 0, w: 0}
|
|
||||||
pivot: {x: 0, y: 0}
|
|
||||||
oldSize: {x: 0, y: 0}
|
|
||||||
newSize: {x: 0, y: 0}
|
|
||||||
adaptiveTilingThreshold: 0
|
|
||||||
drawMode: 0
|
|
||||||
adaptiveTiling: 0
|
|
||||||
m_AutoTiling: 0
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Size: {x: 1, y: 1}
|
|
||||||
m_EdgeRadius: 0
|
|
||||||
--- !u!4 &1986976694
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1986976692}
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: -6.57, y: -0.37200636, z: 3.67}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_RootOrder: 4
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!1001 &1991073249
|
--- !u!1001 &1991073249
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
+63
-40
@@ -17,10 +17,9 @@ public abstract class Character : MonoBehaviour
|
|||||||
|
|
||||||
|
|
||||||
private Rigidbody2D _body;
|
private Rigidbody2D _body;
|
||||||
//private BoxCollider2D _boxCollider;
|
private CapsuleCollider2D _capsuleCollider;
|
||||||
private CapsuleCollider2D _boxCollider;
|
|
||||||
protected bool _isOnBridge;
|
protected bool _isOnBridge;
|
||||||
protected bool _isOnLadder;
|
protected bool _isOnLadder = false;
|
||||||
protected bool _isFalling;
|
protected bool _isFalling;
|
||||||
protected bool _facingRight = true;
|
protected bool _facingRight = true;
|
||||||
|
|
||||||
@@ -28,11 +27,11 @@ public abstract class Character : MonoBehaviour
|
|||||||
protected bool isAllowVertical = true;
|
protected bool isAllowVertical = true;
|
||||||
protected bool isAllowRight = true;
|
protected bool isAllowRight = true;
|
||||||
protected bool isAllowLeft = true;
|
protected bool isAllowLeft = true;
|
||||||
float v_movement = 0;
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
_body = GetComponent<Rigidbody2D>();
|
_body = GetComponent<Rigidbody2D>();
|
||||||
_boxCollider = GetComponent<CapsuleCollider2D>();
|
_capsuleCollider = GetComponent<CapsuleCollider2D>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void MoveTo(float inputHorizontal, float inputVertical)
|
protected void MoveTo(float inputHorizontal, float inputVertical)
|
||||||
@@ -41,8 +40,8 @@ public abstract class Character : MonoBehaviour
|
|||||||
|
|
||||||
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
|
_isOnBridge = mapElement == MapElementType.Bridge && !_isFalling;
|
||||||
|
|
||||||
if (mapElement == MapElementType.Wall || _isOnLadder
|
if (mapElement == MapElementType.Wall)
|
||||||
|| _isOnBridge || mapElement == MapElementType.BreakableWall)
|
//|| _isOnLadder || _isOnBridge || mapElement == MapElementType.BreakableWall)
|
||||||
{
|
{
|
||||||
var leftCheck = GetMapElement(Vector2.left);
|
var leftCheck = GetMapElement(Vector2.left);
|
||||||
var rightCheck = GetMapElement(Vector2.right);
|
var rightCheck = GetMapElement(Vector2.right);
|
||||||
@@ -52,8 +51,8 @@ public abstract class Character : MonoBehaviour
|
|||||||
|
|
||||||
isAllowVertical = false;
|
isAllowVertical = false;
|
||||||
_isFalling = false;
|
_isFalling = false;
|
||||||
|
|
||||||
float h_movement = inputHorizontal;
|
float h_movement = inputHorizontal;
|
||||||
|
|
||||||
if (h_movement > 0 && !_facingRight || h_movement < 0 && _facingRight)
|
if (h_movement > 0 && !_facingRight || h_movement < 0 && _facingRight)
|
||||||
{
|
{
|
||||||
FlipCharacter();
|
FlipCharacter();
|
||||||
@@ -61,25 +60,30 @@ public abstract class Character : MonoBehaviour
|
|||||||
|
|
||||||
SetWalkingAnimation(h_movement != 0);
|
SetWalkingAnimation(h_movement != 0);
|
||||||
|
|
||||||
var upperElement = GetMapElement(Vector2.up);
|
//_isOnLadder = mapElement == MapElementType.Ladder && leftCheck == MapElementType.Ladder && rightCheck== MapElementType.Ladder;
|
||||||
_isOnLadder = mapElement == MapElementType.Ladder || upperElement == MapElementType.Ladder;
|
|
||||||
|
|
||||||
if (_isOnLadder)
|
if (mapElement == MapElementType.Ladder || (leftCheck == MapElementType.Ladder && rightCheck == MapElementType.Ladder))
|
||||||
{
|
{
|
||||||
|
float v_movement = inputVertical;
|
||||||
|
print($"On ladder v_speed {v_movement}");
|
||||||
isAllowVertical = true;
|
isAllowVertical = true;
|
||||||
_isOnLadder = true;
|
_isOnLadder = true;
|
||||||
|
|
||||||
|
//if (v_movement != 0)
|
||||||
|
//{
|
||||||
|
//if (v_movement > 0 && mapElement != MapElementType.Ladder)
|
||||||
|
//{
|
||||||
|
// v_movement = 0;
|
||||||
|
//}
|
||||||
|
|
||||||
float v_movement = inputVertical;
|
SetClimbingAnimation(v_movement != 0);
|
||||||
if (v_movement > 0 && upperElement != MapElementType.Ladder)
|
//}
|
||||||
{
|
|
||||||
v_movement = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetClimbingAnimation(v_movement != 0);
|
|
||||||
_body.velocity = new Vector2(h_movement * MovementSpeed, v_movement * MovementSpeed);
|
_body.velocity = new Vector2(h_movement * MovementSpeed, v_movement * MovementSpeed);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
print("On ground");
|
||||||
_body.velocity = new Vector2(h_movement * MovementSpeed, _body.velocity.y);
|
_body.velocity = new Vector2(h_movement * MovementSpeed, _body.velocity.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,28 +92,7 @@ public abstract class Character : MonoBehaviour
|
|||||||
_isFalling = true;
|
_isFalling = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private MapElementType GetMapElement(Vector2 direction)
|
|
||||||
{
|
|
||||||
var raycastHit = Physics2D.BoxCast(_boxCollider.bounds.center, _boxCollider.bounds.size, 0f, direction, 0.01f, _mapLayer);
|
|
||||||
if (raycastHit)
|
|
||||||
{
|
|
||||||
var mapElement = raycastHit.transform.GetComponent<MapElement>();
|
|
||||||
if (mapElement == null || !mapElement.IsEnabled)
|
|
||||||
{
|
|
||||||
return MapElementType.Empty;
|
|
||||||
}
|
|
||||||
return mapElement.ElementSO.ElementType;
|
|
||||||
}
|
|
||||||
return MapElementType.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void SetWalkingAnimation(bool isWalking);
|
|
||||||
protected abstract void SetClimbingAnimation(bool isClimbing);
|
|
||||||
|
|
||||||
private void FixedUpdate()
|
|
||||||
{
|
|
||||||
if (_isOnLadder || _isOnBridge)
|
if (_isOnLadder || _isOnBridge)
|
||||||
{
|
{
|
||||||
_body.gravityScale = 0;
|
_body.gravityScale = 0;
|
||||||
@@ -123,14 +106,54 @@ public abstract class Character : MonoBehaviour
|
|||||||
_body.velocity = new Vector2(0, _body.velocity.y);
|
_body.velocity = new Vector2(0, _body.velocity.y);
|
||||||
SetWalkingAnimation(false);
|
SetWalkingAnimation(false);
|
||||||
|
|
||||||
if (GetMapElement(Vector2.down) == MapElementType.Ladder)
|
if (mapElement == MapElementType.Ladder)
|
||||||
{
|
{
|
||||||
_body.velocity = Vector2.zero;
|
_body.velocity = Vector2.zero;
|
||||||
_isOnLadder = true;
|
_isOnLadder = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
else
|
||||||
|
rayStartPoint = new Vector2(_capsuleCollider.bounds.center.x + direction.x / 2, _capsuleCollider.bounds.min.y );
|
||||||
|
var boundsSize = new Vector2(_capsuleCollider.bounds.size.x - 0.05f, 0.1f);
|
||||||
|
|
||||||
|
var raycastHit = Physics2D.BoxCast(rayStartPoint, boundsSize, 0f, direction, 1f, _mapLayer);
|
||||||
|
MapElementType returnValue;
|
||||||
|
Color color = Color.red;
|
||||||
|
if (raycastHit)
|
||||||
|
{
|
||||||
|
var mapElement = raycastHit.transform.GetComponent<MapElement>();
|
||||||
|
if (!mapElement.IsEnabled)
|
||||||
|
{
|
||||||
|
color = Color.white;
|
||||||
|
returnValue = MapElementType.Empty;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
color = Color.green;
|
||||||
|
returnValue = mapElement.ElementSO.ElementType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
returnValue = MapElementType.Empty;
|
||||||
|
}
|
||||||
|
Debug.DrawRay(rayStartPoint, direction, color);
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void SetWalkingAnimation(bool isWalking);
|
||||||
|
protected abstract void SetClimbingAnimation(bool isClimbing);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void FlipCharacter()
|
private void FlipCharacter()
|
||||||
{
|
{
|
||||||
Vector3 currentScale = gameObject.transform.localScale;
|
Vector3 currentScale = gameObject.transform.localScale;
|
||||||
|
|||||||
Reference in New Issue
Block a user