0 votes

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([ path.get_point_in(i), path.get_point_position(i), path.get_point_out(i) ]) draw_polyline(points, Color(0.4,0.4,0.4), 1.0) draw_circle(points[0], 2, Color(0.4,0.4,1.0)) draw_circle(points[1], 2, Color(0.4,1.0,0.4)) draw_circle(points[2], 2, Color(1.0,0.4,0.4)) draw_string(font, points[1], 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() rand.set_seed(rng_seed) var base_curve : Curve2D = Curve2D.new() var adv_curve : Curve2D = Curve2D.new() base_curve.set_bake_interval(99999) adv_curve.set_bake_interval(40) 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)) base_curve.add_point(current_position, Vector2(50,0)) # 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)) base_curve.add_point(next_position) print(str(index)+str(current_position)+str(next_position)) current_position = next_position for index in base_curve.get_point_count(): adv_curve.add_point( base_curve.get_point_position(index), base_curve.interpolatef(index-0.3), base_curve.interpolatef(index+0.3) )

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?

Godot version 3.4.stable
in Engine by (22 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.