How to close a Path3D?

Godot Version

4.3

Question

I want to draw a Path3D that holds a Curve3D in the shape of a circle, so that other objects can follow it, in a loop. However, I’m struggling to close the path properly in a way that the last point connects to the first one. Not only in position, but also in direction.

var r = 1
var resolution = 12

for i in range(resolution):
	var angle = -float(i) / resolution * TAU
	curve.add_point(Vector3(r * cos(angle), 0, r * sin(angle)))

path.curve = curve

I have already tried to simply add the first point again, but this creates a “hiccup” in the path and the objects won’t smoothly follow it:

curve.add_point(curve.get_point_position(0))

How can I properly “close” the path so that it appears like a perfect circle?

(Why don’t you just rotate around an axis? Because the path will alter its shape throughout the game into a more complex one.)

This should work. Can you describe what you mean by “hiccup”?

By “hiccup” I’m referring to the anomaly displayed within the red square on my second screenshot. This is causing the path-following object’s rotation to suddenly “jump” from the end of the path to the beginning. It visually almost looks like a drop in FPS (which it isn’t, of course).

Although the last and the first points share the same position, it appears as if they aren’t properly looking at each other, like the other ones do. Causing the rotation to “flicker”.

1 Like

Ah, I see it. I’ll look into this for a bit.

1 Like

Looked into this issue some. I found that this is caused by how PathFollow resets its rotational basis on loop.

I have found that increasing the resolution reduces the hiccup. High enough and there’s no hiccup at all.

But, that may not be optimal for your use case. I have found two workarounds each with different trade-offs.

  1. Move your follower node out of the PathFollow3D node. Manually sync position, and Basis.slerp() your follower node’s rotation to PathFollow3D node.
  2. Calculate your curve with a higher resolution at the start and end of the path. The middle of your path can be the target resolution.

There are some trade-offs.

#1 will have a tiny delay depending on the weight of the slerp. Too much weight and you’ll see the hiccup. Too little and your object won’t look ahead on the path.

#2 The object will travel slower at the start and ends than in the middle. You will have to account for the increased density of points. Actually, maybe you don’t with the PathFollow3D.progress property since it’s by distance.

Keep us updated with your progress. Good luck!

Thanks a lot for your efforts looking into this! I can confirm that cranking up the resolution helps. I’ll stick with this as long as there’s no reason not to.

Hmmm this is becoming a real problem: I have a camera that follows the object that follows the path and even when I crank up the resolution, the image “flickers” because the camera “jumps” from the last point of the path to the first one. Also, it does not seem to reflect light at that point the same way as at the rest of the path.

I’m not an expert in paths but from graphic programs I know that paths can be “closed” and the program will interpolate the points in a way that there is no noticable difference between the last and the first point. They just behave like any other point and its siblings.

Should I open a feature request for this? I’m thinking of something like path.close(). And it looks like from outside there is no way to do this myself because Path3D and Curve3D don’t seem to offer the API needed.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.