Inconsistency issues with instantiating points based on distance

Hey all, need a bit of help here.
I made this system that places points behind a moving object when enough space is between it and the last placed point (and draw a line renderer through it to create a rope effect). This has worked perfectly for me, but soon found out the distance between these points is inconsistent, which causes some issues in other scripts. I think it has to do with the framerate, but not sure if that’s true or how I’d fix that.
Does anyone have any ideas perhaps?

void RecordPath()
    {
        if (linePoints.Count > 0)
        {
            if (Vector2.Distance(transform.position, linePoints[0].transform.position) > pointDistance)
            {
                linePoints.Insert(0, Instantiate(linePointPrefab, transform.position, transform.rotation, pointPool));
                linePoints[0].GetComponent<LinePoint>().line1 = linePoints[1].transform;
            }
        }
        else
        {
            linePoints.Insert(0, Instantiate(linePointPrefab, transform.position, transform.rotation, pointPool));
        }
    }

It’s more a result of frame based movement rather than the frame rate. To get a consistent distance between points you can normalize the direction from the last point and multiply it by the required point distance.

Something like this:

        if (Vector3.Distance(transform.position,lastPoint)>pointDistance)
        {
            Vector3 newPoint=lastPoint+(transform.position-lastPoint).normalized*pointDistance;
            Instantiate(point,newPoint,Quaternion.identity);
            lastPoint=newPoint;
        }
1 Like

Can’t thank you enough! It seemed to have worked pretty well. Only issue I’ve noticed is that with really low framerate (if I lock it to something like 20 fps), the points seem to really fall behind the moving object.9863220--1421130--upload_2024-5-30_12-11-26.png

This issue also appears when to hook is too fast… No clue how to fix this either.

To assist you, we need to see your code to understand how, what, and in what sequence things are happening. Right now, we know nothing except that you have placed some points at equal distances.

1 Like

You can record all of the points just as you were in the original post, but then calculate another set of points post facto that consists of positions on the line at fixed time intervals. You just need to know the relative time values of all of the original points you calculated during frame updates, and then calculate the interpolated values over time at certain values of time t between those data points to give yourself the fixed interval values, while maintaining the same trajectory and distance.

Increase pointDistance.