예제 #1
0
    void Move()
    {
        curSpeed = 0;

        float dirX = Input.GetAxisRaw("Horizontal");
        float dirZ = Input.GetAxisRaw("Vertical");

        Vector3 dir = new Vector3(dirX, 0, dirZ).normalized;

        // 걷기
        if (dir != Vector3.zero)
        {
            curSpeed = moveSpeed;

            // 달리기
            if (Input.GetKey(KeyCode.LeftShift) && theStatus.GetCurSp() > 0)
            {
                curSpeed += runSpeed;
                theStatus.DecreaseCurSp(1); // sp 소모
            }
            dir = transform.TransformDirection(dir);

            // 가속
            if (theGravity.IsGrounded())
            {
                moveVelocity = Vector3.Lerp(moveVelocity, dir * curSpeed, accelation);
            }
            else
            {
                moveVelocity = Vector3.Lerp(moveVelocity, dir * curSpeed, accelation * jumpDeAccel);
            }
            theController.Move(moveVelocity * Time.deltaTime);
        }
        // 멈추기
        else
        {
            // 감속
            if (Vector3.SqrMagnitude(moveVelocity) > 0.1f)
            {
                if (theGravity.IsGrounded())
                {
                    moveVelocity = Vector3.Lerp(moveVelocity, Vector3.zero, deAccelation);
                }
                else
                {
                    moveVelocity = Vector3.Lerp(moveVelocity, Vector3.zero, deAccelation * jumpDeAccel);
                }

                theController.Move(moveVelocity * Time.deltaTime);
            }
            // 정지
            else
            {
                moveVelocity = Vector3.zero;
            }
        }
    }