Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // jumping
- if(Input.GetKeyDown(KeyCode.Space) && !jumping && isGrounded)
- {
- jumping = true;
- StartCoroutine(JumpRoutine());
- }
- // moving
- rb.AddForce(transform.forward * Input.GetAxis("Vertical") * speed);
- rb.AddForce(transform.right * Input.GetAxis("Horizontal") * speed);
- // check if can jump
- if (!isGrounded){
- rb.AddForce(-transform.up * gravity);
- }
- IEnumerator JumpRoutine()
- {
- rb.velocity = Vector2.zero;
- float timer = 0;
- while(Input.GetKey(KeyCode.Space) && timer < jumpTime)
- {
- //Add a constant force every frame of the jump
- rb.AddForce(transform.up*jumpStr);
- timer += Time.deltaTime;
- yield return null;
- }
- jumping = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement