프로그래밍 언어/프로그래밍

유니티 점프

오치리 2016. 6. 8.

목차

리지디바디로 점프 - 물리적 점프

GetComponent<Rigidbody>().velocity = new Vector2(GetComponent<Rigidbody>().velocity.x, jump);



리지디바디 사용안하고 점프 - 계산식으로 만든 점프


private Vector3 moveDirection = Vector3.zero;


        Vector3 targetDirection = (new Vector3(CrossPlatformInputManager.GetAxis("Horizontal") * speed, 0f, CrossPlatformInputManager.GetAxis("Vertical") * speed));



if (targetDirection != Vector3.zero)

                {

                    moveDirection = targetDirection;

                    moveDirection = moveDirection.normalized;

                }

                moveSpeed = targetDirection.magnitude * playerSpeed;

                if (controller.isGrounded)

                {

                    verticalSpeed = 0;

                    if (CrossPlatformInputManager.GetButton("Jump") || Input.GetKeyDown(KeyCode.Space))

                    {

                        verticalSpeed = jumpHight; 

                    }

                }

                else

                {

                    verticalSpeed -= gravity * Time.deltaTime;

                }

                Vector3 movement = moveDirection * moveSpeed + new Vector3(0, verticalSpeed, 0);

                movement *= Time.deltaTime;

                controller.Move(movement);

'프로그래밍 언어 > 프로그래밍' 카테고리의 다른 글

[JAVA] 스트림 입출력 형식  (0) 2016.09.30
[유니티] 오브젝트 터치좌표로 이동하기  (0) 2016.06.17
해시 테이블 (hash table)  (0) 2009.01.18
트리  (0) 2009.01.18
연결 리스트 (문장<이름>)  (0) 2009.01.18

댓글