Unity3D - 메모장

quest3dkorea.com


통계 위젯 (화이트)

211
80
136177


Move with Rigidbody Unity3D 스크립트

private void Update() {
        if (Input.GetKey(KeyCode.LeftArrow) && Input.GetKey(KeyCode.RightArrow)) {
            targetHandle = 0;
        } else if (!Input.GetKey(KeyCode.LeftArrow) && !Input.GetKey(KeyCode.RightArrow)) {
            targetHandle = 0;
        }else if (Input.GetKey(KeyCode.LeftArrow) && !Input.GetKey(KeyCode.RightArrow)) {
            targetHandle = -1;
        }else if (!Input.GetKey(KeyCode.LeftArrow) && Input.GetKey(KeyCode.RightArrow)) {
            targetHandle = 1;
        }

        if (Input.GetKey(KeyCode.UpArrow)) {
            targetForwardSpeed = 1;
        } else if (Input.GetKey(KeyCode.DownArrow)) {
            targetForwardSpeed = -1;
        } else {
            targetForwardSpeed = 0;
        }

        handle = Mathf.Lerp(handle, targetHandle, Time.deltaTime * rotationSpeed);
        rotation = new Vector3(0, handle, 0);

        forwardSpeed = Mathf.Lerp(forwardSpeed, targetForwardSpeed, Time.deltaTime);

        RB.MovePosition(transform.position + transform.forward * (forwardSpeed * speed));

        transform.Rotate(rotation);
    }

덧글

댓글 입력 영역