ThePat02 / BehaviourToolkit

A collection of tools for AI Behaviour in the Godot 4 Game Engine!
MIT License
303 stars 12 forks source link

Input? #60

Closed Shadowblitz16 closed 6 months ago

Shadowblitz16 commented 6 months ago

How would I handle input via behavior trees?

ThePat02 commented 6 months ago

What are you referring to specifically? You can handle inputs any way you like when extending States/Transitions/leaves

Shadowblitz16 commented 6 months ago

What are you referring to specifically? You can handle inputs any way you like when extending States/Transitions/leaves

I wanted to handle inputs in a reusable way. I just don't know how to actually implement it.

How would I build up a input vector and apply it to velocity using behavour trees?

ThePat02 commented 6 months ago

I wanted to handle inputs in a reusable way. I just don't know how to actually implement it.

You can take a look at the example scene in the 2.0.0 (#57) branch. I handle the vectors simply on the Character using

func _physics_process(_delta):
    movement_direction = Vector2(
        Input.get_axis("ui_left", "ui_right"),
        Input.get_axis("ui_up", "ui_down")
    )

and apply it in the FSMState script that is used for the walking state. This relies on the Character having a movement_direction var, but you can easily write your own reusable component/class for the character that is accessed in the BT or FSM too!

Shadowblitz16 commented 6 months ago

I really don't want to have invisible dependencies though. using a script on a node seems like it would defeat the point of a behavior tree

ThePat02 commented 6 months ago

using a script on a node seems like it would defeat the point of a behavior tree

You can always move the same code into the BT nodes!

ThePat02 commented 6 months ago

(Using a blackboard to store the value, if that isn't obvious haha)