728x90
반응형

 

미리보기

구현 기능

1. 낮은 점프

2. 점프 중 입력이 없으면 천천히 정지

3. 점프 중 이동 제약

 

 

1. 낮은 점프

게임 중에는 점프를 누른 시간에 따라 점프의 높이가 달라지는 종류들이 있다.

이것을 간단하게나마 구현한다.

 

if(Input.GetKeyUp(KeyCode.K))
{
    rb.velocity = new Vector3(rb.velocity.x, rb.velocity.y * variableJumpHeightMultiplier, 0);
}

만약 점프키를 뗀다면(Key Up) Rigidbody의 y velocity를 줄인다.

variableJumpHeightMultiplier는 임의로 0.7로 설정하였다.

 

2. AirDrag

점프해서 공중에 있을 때 아무런 입력이 없다면 유저가 더 움직일 의향이 없다고 간주한다.

점프해서 공중에 있을 때 속도를 줄인다.

if(!isGrounded && movementInputDirection == 0)
{
    rb.velocity = new Vector3(rb.velocity.x * airDragMultiplier, rb.velocity.y, rb.velocity.z);
}

 

3. 점프 중 이동 제약

원래 공중에서는 거의 움직일 수 없으나 게임적으로 허용하는 것이다.

점프를 하고 나면 공중에서는 잘 움직이지 않고 방향 전환에 시간이 걸린다.

 

if(!isGrounded && movementInputDirection != 0)
{
    Vector3 forceToAdd = new Vector3(movementForceInAir * movementInputDirection, 0, 0);
    rb.AddForce(forceToAdd);

    if(Mathf.Abs(rb.velocity.x) > movementSpeed)
    {
        rb.velocity = new Vector3(movementSpeed * movementInputDirection, rb.velocity.y, rb.velocity.z);
    }
}

공중에 있고 입력이 있다면 해당 방향으로 AddForce해준다.

아마 버니합을 방지하기 위해 movementSpeed 이상으로는 못올라가게 한 것 같다.

 

AirDrag와 비슷하면서 다르다.

 

마무리

이번 챕터에서는 많이 건드릴 건 없었고 코드 수정만 해서 글이 좀 짧은 것 같다.

다음에는 WallJump를 구현할 예정