Originally, my problem was when I generated a Curve2D and its control points purely with code, the resulting curve would be the complete wrong shape. I detailed my original problem in this reddit post, but further investigation has uncovered something really strange.
While I was attempting to figure out what the problem was, I created a Curve2D in the editor and used that instead of my generated Curve2D.
That curve looks like this (in editor): image
In game, with my custom drawing code, it looks like this: image
And my curve, with the custom drawing code: image
This is the (relevant part of the) drawing code:
draw_polyline(path.get_baked_points(), Color(0.96,0.91,0.14), 1.0)
for i in range(path.get_point_count()):
var points = PoolVector2Array([
draw_polyline(points, Color(0.4,0.4,0.4), 1.0)
draw_circle(points, 2, Color(0.4,0.4,1.0))
draw_circle(points, 2, Color(0.4,1.0,0.4))
draw_circle(points, 2, Color(1.0,0.4,0.4))
draw_string(font, points, str(i))
Obviously, not as efficient as it could be. But this code draws based on exact vector coordinates for every part of the Curve2D. However, my generation code also does this.
My generation code is as follows:
var rand : RandomNumberGenerator = RandomNumberGenerator.new()
var base_curve : Curve2D = Curve2D.new()
var adv_curve : Curve2D = Curve2D.new()
var length : int = rand.randi_range(10,20)
var current_position : Vector2 = Vector2()
# First point
var next_position = current_position + Vector2(rand.randi_range(400,600), rand.randi_range(-200,200))
# Second to second last points
for index in range(length):
next_position = current_position + Vector2(rand.randi_range(400,600), rand.randi_range(-200,200))
current_position = next_position
for index in base_curve.get_point_count():
Looking back to the curve in editor (image 1), those are the control points I expected to have to generate. However, in the second image, those control points are vastly different.
My question is: why do these two differ, and how can I adjust for that in my code?