Example #1
0
    //does a first time set up each time a new level is loaded/reloaded- called by level manager
    public void SetupCalibration()
    {
        GameObject ball = GameObject.FindGameObjectWithTag("Player");

        rbBall          = ball.GetComponent <Rigidbody> ();
        ballInputReader = ball.GetComponent <BallInputReader> ();

        RequestToBeShown();
    }
Example #2
0
    private void FreezeBall()
    {
        //freeze ball
        GameObject ball = GameObject.FindGameObjectWithTag("Player");

        Debug.Log("Ball is " + ball.GetInstanceID());
        rbBall                  = ball.GetComponent <Rigidbody> ();
        ballInputReader         = ball.GetComponent <BallInputReader> ();
        rbBall.isKinematic      = true;
        ballInputReader.enabled = false;
        //ensure scoring is stopped
        ball.GetComponent <TunnelScoreController> ().HaltScoring();
    }
Example #3
0
    private IEnumerator Launch(Rigidbody rb)
    {
        //disable player control of the ball
        BallInputReader ballInput = rb.GetComponent <BallInputReader> ();

        ballInput.enabled = false;
        rb.GetComponent <BrakeController> ().ReleaseBrakes();

        //position ball within the centre of the cannon correctly
        rb.velocity   = Vector3.zero;
        rb.useGravity = false;
        rb.transform.DOMove(this.transform.position + new Vector3(0, 1f, 0), 5f).Play();

        //take control of camera and move it to the right place, player can still pan camera
        AmazeballCam camController            = GameObject.FindGameObjectWithTag("CameraRig").GetComponent <AmazeballCam>();
        ProtectCameraFromWallClip wallClipper = camController.GetComponent <ProtectCameraFromWallClip> ();

        wallClipper.enabled = false;
        float camMoveSpeed = camController.moveSpeed;

        camController.moveSpeed = 0f;
        camController.constrainCameraAngle(camLaunchAngle, 0f, 5f);
        camController.transform.DOLookAt(this.transform.position, 2f).Play();
        camController.movePivot(new Vector3(0f, -2f, 0f));

        //flashing lights etc.
        yield return(new WaitForSeconds(1f));

        StartCoroutine("FlashLight");
        yield return(new WaitForSeconds(1.5f));

        for (int i = 0; i < 4; i++)
        {
            SetEmissionColor(launchLights[i], startColor);
        }
        yield return(new WaitForSeconds(1.5f));

        for (int i = 4; i < launchLights.Length; i++)
        {
            SetEmissionColor(launchLights[i], startColor);
        }
        yield return(new WaitForSeconds(1f));

        StopCoroutine("FlashLight");

        //prepare ball and camera for launching
        rb.useGravity           = true;
        camController.moveSpeed = camMoveSpeed * 2;
        camController.transform.DOLocalRotate(new Vector3(0f, camController.transform.localEulerAngles.y, 0f), 1f).Play();
        camController.movePivot(new Vector3(0f, 2f, 0f));

        //launch ball
        rb.AddForce(Vector3.up * launchPower * rb.mass, ForceMode.Impulse);
        camController.constrainCameraAngle(0f, camAirborneLockAngle, 0f);

        //wait until a VerticalCannonLanding script lets the cannon know the ball has landed
        hasLanded = false;
        while (!hasLanded)
        {
            yield return(new WaitForEndOfFrame());
        }
        //re-enable regular ball control and camera function
        camController.moveSpeed = camMoveSpeed;
        ballInput.enabled       = true;
        wallClipper.enabled     = true;
        camController.removeAngleConstraint();
    }