예제 #1
0
    protected void Jump()
    {
        var dropRCH = Physics2D.CircleCast(transform.position, 0.25f, Vector3.down, 20f, groundLayer);

        if (Input.GetKeyDown(KeyCode.Space) && ground.GroundContact)
        {
            Velocity.y          += JumpSpeed;
            ground.GroundContact = false;
            ground.LastJumpTime  = Time.time;
            Squasher.PlayStretch();
        }

        if (Velocity.y > 0f && !Input.GetKey(KeyCode.Space))
        {
            Velocity.y -= JumpDeceleration * Time.deltaTime;
        }

        if (dropRCH.collider == null || dropRCH.distance > 0.43f)
        {
            Velocity.y -= Gravity * Time.deltaTime;
        }
        else if (Velocity.y < 0f)
        {
            float maxDrop = dropRCH.distance - 0.43f;
            if (Velocity.y < -maxDrop)
            {
                transform.position += Vector3.down * maxDrop;
                if (Mathf.Abs(Velocity.y) > Mathf.Abs(JumpSpeed) / 2f)
                {
                    Squasher.PlaySquash();
                    dustParticle.Play();
                }
                Velocity.y = 0f;
            }
        }
    }