コード例 #1
0
    void checkGround()
    {
        RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, Vector2.down, 1.25f, 1 << 8);

        Debug.DrawRay(transform.position, 1.25f * Vector2.down, Color.green);

        if (hitInfo.collider != null)
        {
            if (resetJump == false)
            {
                playerAnim.Jump(false);
                grounded = true;
            }
        }
    }
コード例 #2
0
ファイル: PlayerMove.cs プロジェクト: shroommu/AlexaEmmaGame
 public void Jump()
 {
     if (isGrounded)
     {
         rigidbody.AddForce(new Vector3(0, jumpSpeed, 0), ForceMode.Impulse);
         isGrounded = false;
         playerAnim.Jump();
     }
 }
コード例 #3
0
    void Update()
    {
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        if (x != 0f || z != 0f)
        {
            playerAnim.Move();
        }
        else
        {
            playerAnim.Idle();
        }

        Vector3 moveDirection = new Vector3(x, 0, z);

        moveDirection  = cameraTransform.TransformDirection(moveDirection);
        moveDirection *= moveSpeed;

        if (characterController.isGrounded == true)
        {
            yVelocity = 0.0f;
            jumpCount = 0;

            if (jumped == true)
            {
                playerAnim.Grounded();
            }
            jumped = false;
        }
        //Debug.Log(characterController.isGrounded);

        if (Input.GetButtonDown("Jump") && jumpCount < 2)
        {
            jumped = true;

            yVelocity = jumpSpeed;

            ++jumpCount;

            playerAnim.Jump();
        }

        yVelocity      += (gravity * Time.deltaTime);
        moveDirection.y = yVelocity;

        //Debug.Log(yVelocity);

        characterController.Move(moveDirection * Time.deltaTime);
    }