//point the pearl based on right analog stick
    void RotatePearlOffset(float x, float y)
    {
        // cancel all input below this
        if (Mathf.Abs(x) < aimingThreshold)
        {
            x = 0.0f;
        }
        if (Mathf.Abs(y) < aimingThreshold)
        {
            y = 0.0f;
        }

        // the player is aiming the pearl
        if (x != 0.0f || y != 0.0f)
        {
            //show the aiming guide
            anim.SetBool("Aiming", true);

            if (inputScript.PlatformIsPC())
            {
                throwAngle = ((Mathf.Atan2(y, x) * Mathf.Rad2Deg) * -1) - 180;                  // for PC
            }
            else
            {
                throwAngle = ((Mathf.Atan2(y, x) * Mathf.Rad2Deg) - 90);                                        // for MAC
            }

            //point the aiming guide in the direction
            pearlOffset.transform.rotation = Quaternion.AngleAxis(throwAngle, Vector3.forward);
        }

        else
        {
            //not aiming, do not show aiming guide on pearl offset, next trow will be in facing dir
            anim.SetBool("Aiming", false);

            if (movingScript.GetFacingRight())
            {
                throwAngle = playerStateScript.GetFacingAngle() - 90;
            }
            else
            {
                throwAngle = playerStateScript.GetFacingAngle() + 90;
            }
        }

        playerStateScript.SetAimingAngle(throwAngle);
    }
Esempio n. 2
0
    void ApplySpeedBoost()
    {
        //increase player speed if they are breathing out
        //find the angle to apply force based on the angle the beaver is facing
        Vector3 dir;

        if (movingScript.GetFacingRight())
        {
            dir = Quaternion.AngleAxis((playerStateScript.GetFacingAngle() - 90f), Vector3.forward) * Vector3.up;
        }
        else
        {
            dir = Quaternion.AngleAxis((playerStateScript.GetFacingAngle() - 270f), Vector3.forward) * Vector3.up;
        }

        //apply force to the pearl in that direction
        GetComponent <Rigidbody2D> ().AddForce(dir * boostVelocity);
    }
Esempio n. 3
0
    void Update()
    {
        switch (dashState)
        {
        case DashState.Dashing:
            //show the player dashing animation
            animator.SetBool("is_dashing", true);


            dashTimer += Time.deltaTime * 5;
            if (dashTimer >= maxDash)
            {
                //stop the player dashing animation
                animator.SetBool("is_dashing", false);
                //changing player state
                playerStateScript.SetIsDashing(false);

                dashTimer = maxDash;
                //r_body.velocity = savedVelocity;
                dashState = DashState.Cooldown;
            }
            break;

        case DashState.Cooldown:

            dashTimer -= Time.deltaTime;
            if (dashTimer <= 0)
            {
                dashTimer = 0;
                dashState = DashState.Ready;
            }
            break;

        case DashState.Ready:
            //if dash button is pressed, set velocity...
            if (dashInputScript.GetDashButton())
            {
                if (!playerStateScript.GetHasPearl() && !playerStateScript.GetIsHit())
                {
                    // savedVelocity = r_body.velocity;


                    //find the angle to dash based on the angle player is facing
                    Vector3 dir;
                    if (movingScript.GetFacingRight())
                    {
                        dir = Quaternion.AngleAxis(playerStateScript.GetFacingAngle() - 90f, Vector3.forward) * Vector3.up;
                    }
                    else
                    {
                        dir = Quaternion.AngleAxis(playerStateScript.GetFacingAngle() - 270f, Vector3.forward) * Vector3.up;
                    }


                    //apply force to the player in that direction
                    GetComponent <Rigidbody2D>().AddForce(dir * dashVelocity);

                    //adding the dash burst to the player velocity
                    //r_body.AddForce(new Vector2(dashVelocity * 1f, dashVelocity * 1f));
                    //changing player state
                    playerStateScript.SetIsDashing(true);

                    dashState = DashState.Dashing;

                    //splashSound.Play();
                    soundPlayer.PlayClip(dashSound, 1.0f);
                }
            }
            break;
        }
    }