티스토리 뷰

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

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
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함