doc: Explain task anatomy

This commit is contained in:
Serhii Snitsaruk 2023-10-31 15:48:52 +01:00
parent 6e6e9985b2
commit e8ae3e7b8f
1 changed files with 39 additions and 2 deletions

View File

@ -26,7 +26,44 @@ Behavior Trees handle conditional logic using condition tasks. These tasks check
Check out the `BTTask` class documentation in the editor, which provides the foundation for various building blocks of Behavior Trees.
## Custom task example
## Creating custom tasks in GDScript
>**🛈 Note:** You can add a script template to your project with "Misc → Create script template" menu option.
### Task anatomy
```
@tool
extends BTAction
# Task parameters.
@export var parameter1: float
@export var parameter2: Vector2
## Note: Each method declaration is optional.
## At minimum, you only need to define the "_tick" method.
# Called to generate a display name for the task.
func _generate_name() -> String:
return "MyTask"
# Called to initialize the task.
func _setup() -> void:
pass
# Called when task is entered.
func _enter() -> void:
pass
# Called when task is exited.
func _exit() -> void:
pass
# Called each time this task is ticked (aka executed).
func _tick(delta: float) -> Status:
return SUCCESS
```
### Custom task example
```gdscript
@tool
@ -51,7 +88,7 @@ func _generate_name() -> String:
LimboUtility.decorate_var(target_var)]
# Called once to initialize the task.
# Called to initialize the task.
func _setup() -> void:
_min_distance_squared = distance_min * distance_min
_max_distance_squared = distance_max * distance_max