Ejemplo n.º 1
0
 // Method to set specific vectors to shoot a curved ball
 private void SetQuadraticCuvedBallData(Vector2 startingVector, Vector2 mVector, Vector2 endingVector)
 {
     curveData = new QuadraticCurveData()
     {
         startVector  = startingVector,
         middleVector = mVector,
         endVector    = endingVector
     };
 }
Ejemplo n.º 2
0
    // Method to curve the ball in the X axis based on a Quadratic Bezier Curve
    private void CurveQuadraticBall(float time, QuadraticCurveData curveData)
    {
        Vector3 curve = this.CalculateQuadraticBezierCurve(
            time,
            Camera.main.ScreenToWorldPoint(new Vector3(curveData.startVector.x, curveData.startVector.y, 1)),
            Camera.main.ScreenToWorldPoint(new Vector3(curveData.middleVector.x, curveData.middleVector.y, 1)),
            Camera.main.ScreenToWorldPoint(new Vector3(curveData.endVector.x, curveData.endVector.y, 1))
            );

        // We curve the ball in the X axis based on the time elapsed since the ball was shot
        gameObject.transform.position += new Vector3(curve.x - gameObject.transform.position.x, 0f, 0f);
    }