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.
- Move your follower node out of the PathFollow3D node. Manually sync position, and
Basis.slerp()
your follower node’s rotation to PathFollow3D node.
- 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.