fix: 캐릭터 이동시 떨어지는 구간의 부자연스러운 이동 수정
This commit is contained in:
@@ -107,7 +107,7 @@ BoxCollider2D:
|
|||||||
adaptiveTiling: 0
|
adaptiveTiling: 0
|
||||||
m_AutoTiling: 0
|
m_AutoTiling: 0
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Size: {x: 0.25, y: 0.15}
|
m_Size: {x: 0.2, y: 0.1}
|
||||||
m_EdgeRadius: 0
|
m_EdgeRadius: 0
|
||||||
--- !u!114 &6824007025137790925
|
--- !u!114 &6824007025137790925
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@@ -121,9 +121,6 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 75a6dd00ee9c3d7428cae5700b2cc666, type: 3}
|
m_Script: {fileID: 11500000, guid: 75a6dd00ee9c3d7428cae5700b2cc666, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
groundLayer:
|
|
||||||
serializedVersion: 2
|
|
||||||
m_Bits: 512
|
|
||||||
--- !u!1 &2757306338607502731
|
--- !u!1 &2757306338607502731
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -374,7 +371,6 @@ MonoBehaviour:
|
|||||||
speed: 3
|
speed: 3
|
||||||
jumpForce: 8
|
jumpForce: 8
|
||||||
airControl: 0.8
|
airControl: 0.8
|
||||||
sideCheckDistance: 0.5
|
|
||||||
groundCheck: {fileID: 427864611187260801}
|
groundCheck: {fileID: 427864611187260801}
|
||||||
groundCheckRadius: 0.1
|
groundCheckRadius: 0.1
|
||||||
groundLayer:
|
groundLayer:
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ BoxCollider2D:
|
|||||||
adaptiveTiling: 0
|
adaptiveTiling: 0
|
||||||
m_AutoTiling: 0
|
m_AutoTiling: 0
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Size: {x: 0.25, y: 0.15}
|
m_Size: {x: 0.2, y: 0.1}
|
||||||
m_EdgeRadius: 0
|
m_EdgeRadius: 0
|
||||||
--- !u!114 &6530647677844077835
|
--- !u!114 &6530647677844077835
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
|
|||||||
@@ -116,23 +116,21 @@ namespace TON
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 기본 이동 속도 계산
|
// 기본 이동 속도 계산
|
||||||
float newVelocityX = horizontalInput * (isGrounded ? speed : speed * airControl);
|
float newVelocityX = horizontalInput * speed;
|
||||||
|
|
||||||
// 경사로 감지
|
// 경사로 감지
|
||||||
bool isOnSlope = false;
|
bool isOnSlope = false;
|
||||||
Vector2 rayOrigin = rb.position;
|
Vector2 rayOrigin = rb.position;
|
||||||
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.down, 1.1f);
|
RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.down, 1.1f);
|
||||||
|
|
||||||
if (!isGrounded) // Ground 충돌 확인
|
|
||||||
|
float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
|
||||||
|
if (slopeAngle > 0 && slopeAngle <= 45f)
|
||||||
{
|
{
|
||||||
float slopeAngle = Vector2.Angle(hit.normal, Vector2.up);
|
isOnSlope = true;
|
||||||
if (slopeAngle > 0 && slopeAngle <= 45f)
|
// 경사면 방향 벡터 계산
|
||||||
{
|
Vector2 slopeDirection = new Vector2(hit.normal.y, -hit.normal.x);
|
||||||
isOnSlope = true;
|
rb.velocity = slopeDirection * (newVelocityX / Mathf.Cos(slopeAngle * Mathf.Deg2Rad));
|
||||||
// 경사면 방향 벡터 계산
|
|
||||||
Vector2 slopeDirection = new Vector2(hit.normal.y, -hit.normal.x);
|
|
||||||
rb.velocity = slopeDirection * (newVelocityX / Mathf.Cos(slopeAngle * Mathf.Deg2Rad));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 경사가 아닐 경우 일반 이동 적용
|
// 경사가 아닐 경우 일반 이동 적용
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ namespace TON
|
|||||||
{
|
{
|
||||||
public bool IsWallTouching { get; private set; }
|
public bool IsWallTouching { get; private set; }
|
||||||
|
|
||||||
private void OnTriggerStay2D(Collider2D other)
|
private void OnTriggerStay2D(Collider2D collision)
|
||||||
{
|
{
|
||||||
IsWallTouching = other.gameObject.layer == LayerMask.NameToLayer("Ground");
|
IsWallTouching = collision.gameObject.layer == LayerMask.NameToLayer("Ground");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTriggerExit2D(Collider2D other)
|
private void OnTriggerExit2D(Collider2D collision)
|
||||||
{
|
{
|
||||||
if (other.gameObject.layer == LayerMask.NameToLayer("Ground"))
|
if (collision.gameObject.layer == LayerMask.NameToLayer("Ground"))
|
||||||
{
|
{
|
||||||
IsWallTouching = false;
|
IsWallTouching = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user