https://github.com/viniciusgerevini/godot-behavior-tree-example
Example of tree implemented in Godot, without extra plugins
https://github.com/viniciusgerevini/godot-behavior-tree-example
Last synced: 2 months ago
JSON representation
Example of tree implemented in Godot, without extra plugins
- Host: GitHub
- URL: https://github.com/viniciusgerevini/godot-behavior-tree-example
- Owner: viniciusgerevini
- License: mit
- Created: 2020-10-12T11:29:42.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-04T01:18:50.000Z (over 2 years ago)
- Last Synced: 2025-02-03T16:47:50.383Z (4 months ago)
- Language: GDScript
- Size: 40 KB
- Stars: 97
- Watchers: 7
- Forks: 17
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Godot Behavior Tree Example
In this project you will find an example o Behavior Tree implemented in Godot, without extra plugins.
You can find the basic nodes under `/addons/behavior_tree`. Custom code is on `/bt_example`.
This example was created for this video: https://www.youtube.com/watch?v=YHUQY2Kea9U
## What is this Behavior Tree doing
### Main example
`./bt_example/main.tscn`
- Follow mouse cursor when close (less than 300px).
- Go to the closest home, in case mouse is too far.
- After reaching home, changes npcs color to red.### Patrol examples
- `./bt_example/patrol_example.tscn`: NPC patrols between two nodes.
- `./bt_example/patrol_example_multiple_points.tscn`: NPC patrols following a list of nodes.
- `./bt_example/patrol_example_path_2d.tscn`: NPC patrols following a Path2D.## Notes
### _physics_process vs _process
In Godot, `_physics_process` is called a fixed amount of times in a second (default 60). `_process` runs every single frame and the amount of times it's called depends on your game FPS which is affected by many factors (processing, GPU, monitor refresh rate).
In this implementation, the behaviour tree tick is called on `_physics_process`, because `_process` caused some weird behaviour in my game. I believe physics process is what you would want to use, but if you wish to change it, the root call is on `./addons/behavior_tree/nodes/bt_root.gd`.
### Is this production ready?
This is just an example. I've been using the same implementation in the game I'm working on and I haven't run in any issues so far. However, this doesn't mean this would work for everyone. Feel free, to use it and change it as you see fit.