Calculating and drawing trajectory. I need mathematician

I have a code of moving GO to points that player clicked. How can I draw his trajectory after clicking the points but before moving. Help me please. I need mathematician to make some formula to calculate the trajectory

var minSpeed : float = 10;
var maxSpeed : float = 50;
var moveSpeed : float;
var accSpeed : float = 20;
var breakSpeed : float = 40;
var rotateSpeed : float = 2;
var breakDist : float = 30;
private var targPos : Vector3;

function Update () {
                targPos = tarPoints[0]; //massive with clicked points.
                var targDir = targPos - transform.position;
                var targDist = Vector3.Distance(transform.position, targPos);


                //If distance more then 3
                if (targDist > 3) {
                        transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(targDir), rotateSpeed * Time.deltaTime); //rotating
                        
                        
                        //Moving forward
                        transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
                        
                        //Accelerating. if not braking
                        if(moveSpeed < maxSpeed && !breaking){
                                
                                        moveSpeed += accSpeed * Time.deltaTime;
                        }
                        
                        //Braking
                        if(targDist < breakDist && moveSpeed > minSpeed){
                                //at breakDist to last point or if go didn't rotate in time
                                if(tarPoints.length == 1 || Mathf.Abs(Quaternion.Dot (transform.rotation, Quaternion.LookRotation(targDir))) < 0.95){
                                        breaking = true;
                                        moveSpeed -= breakSpeed * Time.deltaTime;
                                }else{
                                        breaking = false;
                                }
                        }else{
                                breaking = false;
                        }
                        
                }

[2363-без+имени-1.jpg|2363]

What you are asking for doesn’t have a purely mathematical solution because of the issues of the direction of the vehicle (at least at the start). You could use a spline path follower like mine and just iterate through the path and draw the points using Vectosity or LineRenderer (see the gizmos in my link which do this trick at edit time). That won’t fix the fact that your follower is pointing the wrong way though.

So if you want to simulate that then you are going to have to run the logic for the follower for real (but inside a loop, not actually moving anything in Update), sample 100 or so positions and then draw a line between each of these.

Like Mike already said, it’s impossible to predict the movement of your objet because of the way you move it. Your smoothing function for the rotation is not frame-independent.

It would be possible if you do all your movement in FixedUpdate since you don’t have fluctuations in the framerate, but’s it’s not an easy task the way you move your objects.

In such a case the easiest but not the most efficient way is to just iterate into the future with a copy of your true values. Since you use object functions like Translate which depends on the current object state (rotation), it’s not possible that way you have it at the moment.

edit

Here’s an example how it could be done.

And here’s how it looks like :wink:

But usually if you really need something like that, do it with splines since it’s more accurate.