What is the best way to implement waypoints?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bishop
:warning: Old Version Published before Godot 3 was released.

What is the best way to implement waypoints?..I’d need “fire” waypoint from a boat at a certain distance ( image bellow ) and change boat rotation ( and speed) in every “shooted” waypoint for the possibility do the corners.
Thank all for help

:bust_in_silhouette: Reply From: Nuno Donato

either an array of vector2 positions or place a bunch of node2ds and iterate through them :slight_smile:

Thanks , I have this ,but I’m still looking for another and maybe a better solution like spawning “shooting” waypoints from boat.

Bishop | 2017-05-24 18:14

:bust_in_silhouette: Reply From: eons

For this case, maybe a Path2D can help, then you can use a PathFollow2Ds to set the position of the waypoint areas changing the offsets, should be easy to edit this way.

You can do this with a single PathFollow2D too or just using the curve and some points/distance you set in another way.

Thank you very much eons,
and that’s the great solution…any chance how I get the position of the individual Path2D points…
i’ll get to them?..i thought it could be ( Path2D points ) directly as a target for a boat or spaceship and waypoint for rotation(faceing) and changing speed…just an idea…more on image bellow

Bishop | 2017-05-25 13:17

If you use PathFollow2Ds you can get a position when changing the offset.


If using just the Path2D, you will need to work on the Curve2D (get_curve).
You can get a point position or the position based on an offset (distance from the origin of the curve), I think all the points on the curve are relative to the Path2D, so, keep that in mind when checking position.

Look at the Curve2D documentation for more details Curve2D — Godot Engine (stable) documentation in English

eons | 2017-05-25 15:06

Thank you very much eons…I will go this way

Bishop | 2017-05-25 17:08

:bust_in_silhouette: Reply From: avencherus

You may want to look into Craig Reynold’s work on steering.

A summary article of some of it can be found here: Understanding Steering Behaviors: Wander | Envato Tuts+

You might be interested in the wander algorithm.

Great avencherus, thank you very much too…i’ll look into it.

Bishop | 2017-05-25 13:20

Oh, for AI, definitely you will want to implement behaviors.

eons | 2017-05-25 15:42

No problem. I see that I didn’t understand your initial question. You want to interpolate between waypoints.

A Path2D would be best if you want to easily implement a curve inside the editor, and you would get smoother rotation if you create a curve.

If it was to be done in code, then interpolation between two way points will give you the distance, based on some alpha value (0 to 100%).

The rotation can be calculated by using the angle of that difference vector. Then atan2(y,x) or vector.angle() should give you the angle towards the next waypoint. Adding and offset of PI in many cases, to orient the sprite to face along that path.

var difference = B - A

var alpha = .5 # Some distance between 0 and 1

var new_waypoint = A + difference * alpha
var new_angle = difference.angle() + PI

avencherus | 2017-05-25 16:09

Yes, thank you very much avencherus,…easier solution for this game is OK,
this game is a simple boat race with a track boundaries and a max 3 NPC boats…i’m still a beginner in GDscript.
…i really appreciate help from as!!

Bishop | 2017-05-25 17:25

@eons
Yes, this is an excellent source for education.

Bishop | 2017-05-25 17:33

You’re welcome Bishop, hope it bears fruit for you. Good luck with your adventure. X)

avencherus | 2017-05-25 17:34