fix: 캐릭터 이동시 떨어지는 구간의 부자연스러운 이동 수정

This commit is contained in:
aube.lee
2025-02-20 14:22:04 +09:00
parent c55c644183
commit 2ba06148a1
4 changed files with 14 additions and 20 deletions

View File

@@ -107,7 +107,7 @@ BoxCollider2D:
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.25, y: 0.15}
m_Size: {x: 0.2, y: 0.1}
m_EdgeRadius: 0
--- !u!114 &6824007025137790925
MonoBehaviour:
@@ -121,9 +121,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 75a6dd00ee9c3d7428cae5700b2cc666, type: 3}
m_Name:
m_EditorClassIdentifier:
groundLayer:
serializedVersion: 2
m_Bits: 512
--- !u!1 &2757306338607502731
GameObject:
m_ObjectHideFlags: 0
@@ -374,7 +371,6 @@ MonoBehaviour:
speed: 3
jumpForce: 8
airControl: 0.8
sideCheckDistance: 0.5
groundCheck: {fileID: 427864611187260801}
groundCheckRadius: 0.1
groundLayer:

View File

@@ -107,7 +107,7 @@ BoxCollider2D:
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 0.25, y: 0.15}
m_Size: {x: 0.2, y: 0.1}
m_EdgeRadius: 0
--- !u!114 &6530647677844077835
MonoBehaviour:

View File

@@ -116,15 +116,14 @@ namespace TON
else
{
// 기본 이동 속도 계산
float newVelocityX = horizontalInput * (isGrounded ? speed : speed * airControl);
float newVelocityX = horizontalInput * speed;
// 경사로 감지
bool isOnSlope = false;
Vector2 rayOrigin = rb.position;
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)
{
@@ -133,7 +132,6 @@ namespace TON
Vector2 slopeDirection = new Vector2(hit.normal.y, -hit.normal.x);
rb.velocity = slopeDirection * (newVelocityX / Mathf.Cos(slopeAngle * Mathf.Deg2Rad));
}
}
// 경사가 아닐 경우 일반 이동 적용
if (!isOnSlope)

View File

@@ -8,14 +8,14 @@ namespace TON
{
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;
}