I want to create a directional line ( curve / linear ) depending where the direction is coming from.

In some games, similar to Angry Birds, a dotted guideline is shown to provide where the gameObject is going.

I want to create something like that. But not from the starting point. When i mean starting point, it simply means a dotted guideline from where the gameObject is released.

What i want is a dotted guideline from the end point. However, this end point is fixed. How i imagine this is, i have a gameObject. When this gameObject is near to land around this end point, it will show the dotted guideline.

Am i asking too much ? Sorry if i am, a structural guideline of how to write this code would be great.



enter image description here

So this how i want it visual. In Diagram ( A ) it shows a dotted line through the whole course of the path.

However what i want is shown in Diagram ( B ). It is split into two parts, a orange and red path. I only want the red path. But for a clear understand i included the red path. I only want the object to land or around that spot of Diagram ( B ).

What i dont want is from Diagram ( C ). Because it is not landing in the spot of Diagram ( B ). I dont want it to show anything. I only want the red dotted line from Diagram to appear when it is near or going to land in that spot of Diagram ( B ).


  • \$\begingroup\$ I'm not really clear what you mean. The dotted line typically indicates the direction the object is heading. A dotted line from a fixed end point would only accurately describe the motion of the object if it was heading directly for the end point. Maybe you can clarify with a image? \$\endgroup\$ – MichaelHouse Dec 9 '14 at 23:45
  • \$\begingroup\$ How are you calculating the path of the object or its landing point? Are you simply firing it and then letting the unity physics do the rest? \$\endgroup\$ – Malrig Dec 9 '15 at 16:50

I happened to be writing a script that draws this kind of preview arc for a workshop I'm putting together:

Physics launching game with preview arc

(Public domain art assets courtesy of Kenney)

Here's the script:

public class PreviewArc : MonoBehaviour {

    public float predictionSeconds = 4f;
    public int subdivisionCount = 20;

    LineRenderer _line;
    Vector3[] _points;

    void Awake ()
        _line = GetComponent<LineRenderer>();
        _points = new Vector3[subdivisionCount];    

    public void Preview(Vector3 startPosition, Vector3 initialVelocity)
        float timeStep = predictionSeconds / _points.Length;
        for(int i = 0; i < _points.Length; i++)
            float t = i * timeStep;

            // Standard ballistic motion:
            Vector3 point = startPosition 
                          + t * initialVelocity 
                          + 0.5f * t * t * (Vector3)(Physics2D.gravity);

            _points[i] = point;


(You can convert this from 3D to 2D by replacing Physics2D with Physics)

To draw only the tail end of the arc, you can do one of two things:

  1. When calling Preview(), pass a startPosition and initialVelocity that match the state of the object at the moment of descent that you want to illustrate

  2. Advance the time window covered by the loop that fills in the _points array so it includes just the segment you want.

eg. float t = i * timeStep + startTime;

|improve this answer|||||

Suppose if you have a curve starting from (0,0) and lands at (100,0). If you only want to draw say 30% of the curve at end, then only draw the segment of curve between x=70 and x=100.

|improve this answer|||||
  • \$\begingroup\$ What other factors are needed to be taken into consideration ? And how would this be done in code ? \$\endgroup\$ – JekasG Dec 10 '14 at 8:06
  • 1
    \$\begingroup\$ Well, you can use math to calculate the starting x and ending x for the segment. As for how to actually draw the curve, you need to investigate the curve drawing function and use math again to do the necessary transformations if required. \$\endgroup\$ – user55564 Dec 10 '14 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.