示例#1
0
    /// <summary>
    /// Draws the path of the shoot from source object current position to
    /// target object current position.
    /// </summary>
    /// <param name="source">Source.</param>
    /// <param name="target">Target.</param>
    /// <param name="gravity">Gravity.</param>
    /// <param name="delta_h">The maximum height of the shoot starting from
    /// target y postion.</param>
    public static void DrawPath(Transform source, Transform target,
                                float gravity, float delta_h)
    {
        ShootData shootData = Kinematic.CalculateShoot(source,
                                                       target,
                                                       gravity,
                                                       delta_h);
        Vector3 previousDrawPoint = source.position;

        int resolution = 30;

        for (int i = 1; i <= resolution; i++)
        {
            float   simulationTime = (i / (float)resolution) * shootData.timeToTarget;
            Vector3 displacement   = shootData.initialVelocity * simulationTime
                                     + Vector3.up * gravity
                                     * simulationTime * simulationTime /
                                     2f;
            Vector3 drawPoint = source.position + displacement;

            // TODO Find a way to draw trajectory not only in debug mode (to be
            //      able to visualizing it in the actual scene, not only in Scene tab)
            Debug.DrawLine(previousDrawPoint, drawPoint, Color.green);
            previousDrawPoint = drawPoint;
        }
    }