#165 전투 플레이어 움직임 보완 작업

+ 전방 장애물 감지 보완
+ 경사면에서 움직임 보완
This commit is contained in:
NTG 2024-02-18 04:40:14 +09:00
parent f70cb282fb
commit 7b4408247e
4 changed files with 120 additions and 57 deletions

View File

@ -12188,6 +12188,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (1) value: SM_staircase (1)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex
@ -97203,6 +97208,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (8) value: SM_staircase (8)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex
@ -267599,6 +267609,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase value: SM_staircase
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex
@ -329270,6 +329285,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (5) value: SM_staircase (5)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex
@ -455325,6 +455345,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (2) value: SM_staircase (2)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex
@ -487855,10 +487880,10 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (7) value: SM_staircase (7)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Layer
value: 0 value: 3
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3339676424458973423, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3339676424458973423, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
@ -492464,6 +492489,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (6) value: SM_staircase (6)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex
@ -553584,6 +553614,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (3) value: SM_staircase (3)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex
@ -724532,6 +724567,11 @@ PrefabInstance:
propertyPath: m_Name propertyPath: m_Name
value: SM_staircase (4) value: SM_staircase (4)
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2671543527693871701, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3}
propertyPath: m_Layer
value: 3
objectReference: {fileID: 0}
- target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196, - target: {fileID: 3013562905558963970, guid: abf04c401523f1e4d93d7e1004a6a196,
type: 3} type: 3}
propertyPath: m_Convex propertyPath: m_Convex

View File

@ -28,16 +28,22 @@ namespace BlueWaterProject
public class CheckOption public class CheckOption
{ {
[Tooltip("지면으로 체크할 레이어 설정")] [Tooltip("지면으로 체크할 레이어 설정")]
public LayerMask groundLayer = -1; public LayerMask groundLayer;
[Tooltip("장애물로 체크할 레이어 설정")]
public LayerMask obstacleLayer = -1;
[Range(0.01f, 0.5f), Tooltip("전방 감지 거리")] [Range(0.01f, 0.5f), Tooltip("전방 감지 거리")]
public float forwardCheckDistance = 0.1f; public float forwardCheckDistance = 0.1f;
[Range(0.0f, 0.5f), Tooltip("전방 지면 인식 허용 거리")]
public float forwardCheckThreshold = 0.4f;
[Range(0.1f, 10.0f), Tooltip("지면 감지 거리")] [Range(0.1f, 10.0f), Tooltip("지면 감지 거리")]
public float groundCheckDistance = 2.0f; public float groundCheckDistance = 2.0f;
[Range(0.0f, 0.5f), Tooltip("지면 인식 허용 거리")] [Range(0.0f, 1f), Tooltip("지면 인식 허용 거리")]
public float groundCheckThreshold = 0.01f; public float groundCheckThreshold = 0.2f;
} }
[Serializable] [Serializable]
@ -47,10 +53,10 @@ namespace BlueWaterProject
public float moveSpeed = 10f; public float moveSpeed = 10f;
[Range(1f, 75f), Tooltip("등반 가능한 경사각")] [Range(1f, 75f), Tooltip("등반 가능한 경사각")]
public float maxSlopeAngle = 50f; public float maxSlopeAngle = 30f;
[Range(1f, 50f), Tooltip("대쉬 속도")] [Range(1f, 50f), Tooltip("대쉬 속도")]
public float dashSpeed = 30f; public float dashSpeed = 20f;
[Range(0.1f, 1f), Tooltip("대쉬 시간")] [Range(0.1f, 1f), Tooltip("대쉬 시간")]
public float dashTime = 0.2f; public float dashTime = 0.2f;
@ -119,16 +125,15 @@ namespace BlueWaterProject
get => MyCurrentState.isStunned; get => MyCurrentState.isStunned;
set => MyCurrentState.isStunned = value; set => MyCurrentState.isStunned = value;
} }
private float capsuleRadiusDifferent;
private float castRadius;
private Vector3 CapsuleTopCenterPoint => new(transform.position.x, private Vector3 CapsuleTop => MyComponents.rb.position + (MyComponents.capsuleCollider.center +
transform.position.y + MyComponents.capsuleCollider.height - MyComponents.capsuleCollider.radius, Vector3.up * (MyComponents.capsuleCollider.height * 0.5f - MyComponents.capsuleCollider.radius))
transform.position.z); * transform.localScale.x;
private Vector3 CapsuleBottom => MyComponents.rb.position + (MyComponents.capsuleCollider.center -
private Vector3 CapsuleBottomCenterPoint => new(transform.position.x, Vector3.up * (MyComponents.capsuleCollider.height * 0.5f - MyComponents.capsuleCollider.radius))
transform.position.y + MyComponents.capsuleCollider.radius, * transform.localScale.x;
transform.position.z); private float CapsuleRadius => MyComponents.capsuleCollider.radius * transform.localScale.x * 0.9f;
private float CapsuleHeight => MyComponents.capsuleCollider.height * transform.localScale.y;
public static readonly int IsDashingHash = Animator.StringToHash("isDashing"); public static readonly int IsDashingHash = Animator.StringToHash("isDashing");
@ -184,15 +189,10 @@ namespace BlueWaterProject
if (!TryGetComponent(out MyComponents.capsuleCollider)) if (!TryGetComponent(out MyComponents.capsuleCollider))
{ {
MyComponents.capsuleCollider = gameObject.AddComponent<CapsuleCollider>(); MyComponents.capsuleCollider = gameObject.AddComponent<CapsuleCollider>();
MyComponents.capsuleCollider.height = 2f; MyComponents.capsuleCollider.height = 2f;
MyComponents.capsuleCollider.center = Vector3.up; MyComponents.capsuleCollider.center = Vector3.up;
MyComponents.capsuleCollider.radius = 0.5f; MyComponents.capsuleCollider.radius = 0.5f;
} }
var capsuleColliderRadius = MyComponents.capsuleCollider.radius;
castRadius = capsuleColliderRadius * 0.9f;
capsuleRadiusDifferent = capsuleColliderRadius - castRadius + 0.05f;
} }
private void InitStartValue() private void InitStartValue()
@ -282,10 +282,10 @@ namespace BlueWaterProject
MyCurrentValue.groundNormal = Vector3.up; MyCurrentValue.groundNormal = Vector3.up;
MyCurrentValue.groundSlopeAngle = 0f; MyCurrentValue.groundSlopeAngle = 0f;
MyCurrentValue.forwardSlopeAngle = 0f; MyCurrentValue.forwardSlopeAngle = 0f;
var groundRaycast = Physics.SphereCast(CapsuleBottomCenterPoint, castRadius,Vector3.down, var groundRaycast = Physics.CapsuleCast(CapsuleBottom, CapsuleTop, CapsuleRadius,
out var hit, MyCheckOption.groundCheckDistance, MyCheckOption.groundLayer, QueryTriggerInteraction.Ignore); Vector3.down, out var hit, MyCheckOption.groundCheckDistance, MyCheckOption.groundLayer, QueryTriggerInteraction.Ignore);
MyCurrentState.isGrounded = false; MyCurrentState.isGrounded = false;
if (groundRaycast) if (groundRaycast)
@ -295,22 +295,8 @@ namespace BlueWaterProject
MyCurrentValue.forwardSlopeAngle = Vector3.Angle(MyCurrentValue.groundNormal, MyCurrentValue.currentMoveDirection) - 90f; MyCurrentValue.forwardSlopeAngle = Vector3.Angle(MyCurrentValue.groundNormal, MyCurrentValue.currentMoveDirection) - 90f;
MyCurrentState.isOnSlope = MyCurrentValue.groundSlopeAngle > 0f && MyCurrentValue.groundSlopeAngle < MyMovementOption.maxSlopeAngle; MyCurrentState.isOnSlope = MyCurrentValue.groundSlopeAngle > 0f && MyCurrentValue.groundSlopeAngle < MyMovementOption.maxSlopeAngle;
MyCurrentState.isOnSteepSlope = MyCurrentValue.groundSlopeAngle >= MyMovementOption.maxSlopeAngle; MyCurrentState.isOnSteepSlope = MyCurrentValue.groundSlopeAngle >= MyMovementOption.maxSlopeAngle;
MyCurrentValue.groundDistance = Mathf.Max(hit.distance, 0f);
// 경사각 이중검증 (수직 레이캐스트) : 뾰족하거나 각진 부분 체크 MyCurrentState.isGrounded = MyCurrentValue.groundDistance <= MyCheckOption.groundCheckThreshold;
//if (State.isOnSteepSlope)
//{
// Vector3 ro = hit.point + Vector3.up * 0.1f;
// Vector3 rd = Vector3.down;
// bool rayD =
// Physics.SphereCast(ro, 0.09f, rd, out var hitRayD, 0.2f, COption.groundLayerMask, QueryTriggerInteraction.Ignore);
// Current.groundVerticalSlopeAngle = rayD ? Vector3.Angle(hitRayD.normal, Vector3.up) : Current.groundSlopeAngle;
// State.isOnSteepSlope = Current.groundVerticalSlopeAngle >= MOption.maxSlopeAngle;
//}
MyCurrentValue.groundDistance = Mathf.Max(hit.distance - capsuleRadiusDifferent - MyCheckOption.groundCheckThreshold, 0f);
MyCurrentState.isGrounded = (MyCurrentValue.groundDistance <= 0.0001f) && !MyCurrentState.isOnSteepSlope;
GizmosUpdateValue(ref gzGroundTouch, hit.point); GizmosUpdateValue(ref gzGroundTouch, hit.point);
} }
@ -321,17 +307,34 @@ namespace BlueWaterProject
/// <summary> 전방 장애물 검사 : 레이어 관계 없이 trigger가 아닌 모든 장애물 검사 </summary> /// <summary> 전방 장애물 검사 : 레이어 관계 없이 trigger가 아닌 모든 장애물 검사 </summary>
private void CheckForward() private void CheckForward()
{ {
var obstacleRaycast = Physics.CapsuleCast(CapsuleBottomCenterPoint, CapsuleTopCenterPoint, castRadius, var start = MyComponents.rb.position + Vector3.up * (CapsuleHeight - (CapsuleHeight - MyCheckOption.forwardCheckThreshold) * 0.5f);
MyCurrentValue.currentMoveDirection + Vector3.down * 0.1f, var boxScale = new Vector3(CapsuleRadius, (CapsuleHeight - MyCheckOption.forwardCheckThreshold) * 0.5f, CapsuleRadius);
out var hit, MyCheckOption.forwardCheckDistance, -1, QueryTriggerInteraction.Ignore); var raycast = Physics.BoxCast(start, boxScale, MyCurrentValue.currentMoveDirection, out var hit,
Quaternion.identity, MyCheckOption.forwardCheckDistance,MyCheckOption.obstacleLayer, QueryTriggerInteraction.Ignore);
MyCurrentState.isForwardBlocked = false; MyCurrentState.isForwardBlocked = false;
if (obstacleRaycast)
if (raycast)
{ {
var forwardObstacleAngle = Vector3.Angle(hit.normal, Vector3.up); MyCurrentState.isForwardBlocked = true;
MyCurrentState.isForwardBlocked = forwardObstacleAngle >= MyMovementOption.maxSlopeAngle; return;
}
GizmosUpdateValue(ref gzForwardTouch, hit.point); if (MyCurrentState.isOnSteepSlope)
{
start = MyComponents.rb.position + Vector3.up * 0.9f + MyCurrentValue.currentMoveDirection * MyCheckOption.forwardCheckDistance;
boxScale = new Vector3(CapsuleRadius, (CapsuleHeight - 0.4f) * 0.5f, CapsuleRadius);
var raycast2 = Physics.BoxCast(start, boxScale, Vector3.down, out var hit2,
Quaternion.identity, MyCheckOption.groundCheckDistance,MyCheckOption.groundLayer, QueryTriggerInteraction.Ignore);
if (raycast2)
{
var angle = Vector3.Angle(hit2.normal, Vector3.up);
if (angle < MyMovementOption.maxSlopeAngle)
{
MyCurrentState.isOnSteepSlope = false;
}
}
} }
} }
@ -476,8 +479,26 @@ namespace BlueWaterProject
gzGroundTouch + MyCurrentValue.groundCross); gzGroundTouch + MyCurrentValue.groundCross);
Gizmos.color = new Color(0.5f, 1.0f, 0.8f, 0.8f); Gizmos.color = new Color(0.5f, 1.0f, 0.8f, 0.8f);
Gizmos.DrawWireSphere(CapsuleTopCenterPoint, castRadius);
Gizmos.DrawWireSphere(CapsuleBottomCenterPoint, castRadius); // CapsuleCast의 시작과 끝 위치를 표현
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(CapsuleBottom, CapsuleRadius);
Gizmos.DrawWireSphere(CapsuleTop, CapsuleRadius);
// CapsuleCast가 이동할 경로 표현
Gizmos.color = Color.blue;
Gizmos.DrawLine(CapsuleBottom, CapsuleBottom + Vector3.down * MyCheckOption.groundCheckDistance);
Gizmos.DrawLine(CapsuleTop, CapsuleTop + Vector3.down * MyCheckOption.groundCheckDistance);
Gizmos.color = Color.green;
var start = MyComponents.rb.position + Vector3.up * 0.9f +
MyCurrentValue.previousMoveDirection * MyCheckOption.forwardCheckDistance;
var boxScale = new Vector3(CapsuleRadius, (CapsuleHeight - 0.4f) * 0.5f, CapsuleRadius);
Gizmos.DrawWireCube(start, boxScale * 2);
// CapsuleCast의 종료 위치에 대한 캡슐을 표현
//Gizmos.DrawWireSphere(CapsuleBottom + Vector3.down * MyCheckOption.groundCheckDistance, CapsuleRadius);
//Gizmos.DrawWireSphere(CapsuleTop + Vector3.down * MyCheckOption.groundCheckDistance, CapsuleRadius);
} }
[System.Diagnostics.Conditional("UNITY_EDITOR")] [System.Diagnostics.Conditional("UNITY_EDITOR")]

View File

@ -297,9 +297,13 @@ MonoBehaviour:
groundLayer: groundLayer:
serializedVersion: 2 serializedVersion: 2
m_Bits: 8 m_Bits: 8
forwardCheckDistance: 0.1 obstacleLayer:
groundCheckDistance: 2 serializedVersion: 2
groundCheckThreshold: 0.01 m_Bits: 2183374079
forwardCheckDistance: 0.2
forwardCheckThreshold: 0.4
groundCheckDistance: 1
groundCheckThreshold: 0.5
<MyMovementOption>k__BackingField: <MyMovementOption>k__BackingField:
moveSpeed: 10 moveSpeed: 10
maxSlopeAngle: 30 maxSlopeAngle: 30
@ -332,8 +336,6 @@ MonoBehaviour:
stunParticle: {fileID: 1597267395097946864} stunParticle: {fileID: 1597267395097946864}
showGizmos: 1 showGizmos: 1
gizmoRadius: 0.05 gizmoRadius: 0.05
showGUI: 1
guiTextSize: 28
--- !u!1 &5711603842414715359 --- !u!1 &5711603842414715359
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -13,7 +13,7 @@ MonoBehaviour:
m_Name: Rhinoceros m_Name: Rhinoceros
m_EditorClassIdentifier: m_EditorClassIdentifier:
mBehaviorSource: mBehaviorSource:
behaviorName: FieldMinion behaviorName: Rhinoceros
behaviorDescription: behaviorDescription:
mTaskData: mTaskData:
types: [] types: []