Current Godot version: Godot 3.1 beta 1
The purpose of this addon is to create a node which automatically navigates to a given position within a Navigation2D node.
See: https://youtu.be/RnQSdOYMS2g for a demo
To use it, do the following:
- Clone this repository into your project under an addons folder in your resources
- Go to Project Settings -> Plugins (at the top) -> Find Navigator2D and switch it to active
- In your scene where you have a Navigation2D node, add a Navigator2D node as a child of the node you want to move in the Navigation2D.
- On the Navigator2D node, set the NodePath to be equal to your Navigation2D node.
- Go into the script attached to the Navigator2D node and ensure the values that are exported are set to the values you want; things like Speed, whether or not it looks at its target (i.e. rotates to face the target), or whether or not it optimizes the path it creates are variables; feel free to update them to whatever you want. (I'm not sure why these aren't exporting correctly; I will update the plugin when I figure it out, or feel free to create a PR and I'll accept it.)
- When you want to navigate to a particular position, call $Navigator2D.navigate_to(position). The position should be any node that's somewhere in your Navigation2D polygon. Make sure you're attached to the "on_destination_reached" signal; the signal relays to your function the node which was navigating (so the parent of the Navigator2D), as well as the node that was being navigated to. This is useful in case you have scripts on either or both of those nodes and when you've reached your destination, you have to do something specific.
- Pay close attention to the NavigationStopEpsilon; this value will determine at what distance from your destination node it's acceptable to stop moving.
- This does not take into account physics, nor any sort of artificial intelligence, of any kind; it only navigates.