Example #1
0
    void Launch()
    {
        Physics.gravity = Vector3.up * gravity;
        ball.useGravity = true;
        LaunchStruct launchStruct = CalculateLaunchVelocity();

        ball.velocity = launchStruct.velocity;
        Debug.Log(launchStruct.velocity);
    }
Example #2
0
    void DrawPath()
    {
        LaunchStruct ls = CalculateLaunchVelocity();

        Vector3 previousDrawPoint = ball.position;

        for (int i = 0; i <= resolution; i++)
        {
            float   simulationTime = i / (float)resolution * ls.time;
            Vector3 displacement   = (ls.velocity * simulationTime) + (Vector3.up * gravity * Mathf.Pow(simulationTime, 2)) / 2f;
            Vector3 drawPoint      = ball.position + displacement;
            Debug.DrawLine(previousDrawPoint, drawPoint, Color.green);
            previousDrawPoint = drawPoint;
        }
    }