This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Hi...,

I've figured out how Curve3D.get_closest_point(...) works.

How to get the direction at this closest point?

Thanks

Mike

in Engine by (169 points)
edited by

Short answer is(closest_point - current_point).normalize() ... but that is a guess. Please add some code in your question (edit)

hi clemens,

the code lools similar to this:

var curve := Curve3D()
var closest_point = curve.get_closest_point( point_somewhere )

I don't have a current_point on the curve.

Thanks

Mike

I exactly don't know what you want, but i think you need to use curve's
getpointposition(point_index) to get position, and then simply calculate direction vector as CLEMENS.TOLBOOM said:

var curve := Curve3D()
var direction_vector = (curve.get_closest_point( point_somewhere ) -  curve.get_point_position(any_point_number)).normalize()

See more info about Curve3d

hi Falcon,

from where do I get your any_point_number value, and does this make sense?

Thanks

Mike

hi clemens and Falcon,

I have changed my code from get_closest_point to get_closest_offset, which seams to work. Then with interpolate_baked I can calculate the direction like this:

var curve := Curve3D()
var offset = curve.get_closest_offset( point_somewhere )
var point_1 = curve.interpolate_baked( offset, true )
var point_2 = curve.interpolate_baked( offset + 0.01, true )
var direction : Vector3 = ( point_2 - point_1 ).normalized()

Thank you again

Mike

1 Answer

+1 vote
Best answer

Hi again,

I have found a simpler solution. I use a Path with a PathFollow. The PathFollow can be set like this:

pathfollow.offset = path.curve.get_closest_offset( point_somewhere )
var basis = pathfollow.global_transform.basis
var y_direction: float = Vector2( basis.z.x,basis.z.z ).angle_to( Vector2( 0,-1 ) )

I use PathFollow with Rotation Mode = Y, and I can calculate the y_direction by the transform.basis.

Thanks

Mike

by (169 points)
edited by
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 Frequently asked questions and 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 [email protected] with your username.