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

+2 votes

Best answer

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

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 http://docs.godotengine.org/en/stable/classes/class_curve2d.html

0 votes

+1 vote

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

A summary article of some of it can be found here: https://gamedevelopment.tutsplus.com/tutorials/understanding-steering-behaviors-wander--gamedev-1624

You might be interested in the wander algorithm.

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
```

- All categories
- Engine 31,314