Ejemplo n.º 1
0
    /**
     * The player starts dashing.
     */
    private void Dash()
    {
        Vector2 horizontalVelocity = new Vector2(rigidBody.velocity.x, rigidBody.velocity.z);

        if (numDashes > 0 && horizontalVelocity.magnitude > 0.1f)
        {
            if (!dashing)
            {
                // dashVector is the player's joystick direction, relative to the world.
                Vector2 dashVectorForward = new Vector2(transform.forward.x, transform.forward.z) * moveVector.y;
                Vector2 dashVectorRight   = new Vector2(transform.right.x, transform.right.z) * moveVector.x;
                Vector2 dashVector        = (dashVectorForward + dashVectorRight).normalized;

                if (Vector2.Angle(horizontalVelocity, dashVector) < 90)
                {
                    // Add to the player's velocity.
                    Vector2 addedVelocity = horizontalVelocity.normalized * maxSpeed * dashMultiplier;
                    rigidBody.velocity += new Vector3(addedVelocity.x, 0, addedVelocity.y);
                }
                else
                {
                    // Change the player's direction completely.
                    rigidBody.velocity = new Vector3(dashVector.x * maxSpeed * dashMultiplier, rigidBody.velocity.y, dashVector.y * maxSpeed * dashMultiplier);
                }
            }

            dashing = true;
            numDashes--;
            dashCounter = dashLength;
            if (numDashes == 1)
            {
                levelStats.StartDashGaugeAnimation1();
            }
            else
            {
                levelStats.StartDashGaugeAnimation2();
            }

            // If you dash while a dash is reloading, you will lose your progress with reloading the dash.
            dashCooldownCounter = 0f;
            soundManager.PlayDashSound();
            if (cameraParticleSystem)
            {
                cameraParticleSystem.Play();
            }

            // Dashing gives you a very small upward force so that you can dash between platforms and not worry about falling through.
            rigidBody.AddForce(new Vector3(0, jumpForce * dashUpMultiplier, 0), ForceMode.Impulse);
        }
    }