Bezier curve through 3d space

Godot Version

4.5.1.stable

Bezier curve through 3d space

Hello. I want to draw a curve using the following script:

func testSampleBaked() -> void:
	var curve: Curve3D = Curve3D.new()
	curve.bake_interval = 0.75
	for point in points:
		curve.add_point(point)	
	print(str("get_baked_length --> "), str(curve.get_baked_length()))
	var min: float = 0.0	
	var max: float = curve.get_baked_length()
	var actual: float = min
	while actual <= max:
		markIt(curve.sample_baked(actual, true))
		actual += STEP

where ‘points’ is an array of Vector3 (green and blue) and ‘markIt(…)‘ draws a 3d marker at the given position (red). I get this (only a direct connection between all of my points). This is very simple to do and i do not need a Curve3D or anything else like it to get it…

…but as i want to use this curve as a “smoothed“ flight path for an enemy in my game, i of course hoped to achieve something like this:

Can anyone help? Thank you:)

Take a look at Curve3D class reference. add_pont() takes two additional optional arguments that represent in/out tangents. If you don’t supply them you’ll get linear segments.

1 Like

This video “Path Based Mesh Generation in Godot 4” by Crigz Vs Game Dev might be helpful for you I used it to generate railways for my game.

Its OK. I did the right thing, but the given points were to close to each other so that there was not enough place to “bezier“ between them. After giving more space to the points:

1 Like