ThePat02 / BehaviourToolkit

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

Tween Leaves #25

Closed squk closed 10 months ago

squk commented 10 months ago

Some general purpose utility leaves for behavior trees would be nice to have. I'm not sure how abstract they can be made given the limitations of Godot's editor(e.g. no support for Variant @export properties).

I think 1 leaf for each node property type that can be tweened would be useful? So, TweenVector3, TweenVector2, TweenInt etc.

Or you could maybe accomplish the same thing with a few Tween leafs for each primitive type in Godot:?

class_name TweenFloatProperty extends BTLeaf

@export var transition_type: Tween.TransitionType = Tween.TransitionType.TRANS_SINE
@export var ease_type: Tween.EaseType = Tween.EaseType.EASE_IN
@export var tween_property: String = "rotation:y"
@export var tween_value: float = 0.0
@export var duration: float = 2.0

var tween : Tween
func tick(actor: Node, _blackboard: Blackboard) -> Status:
    _init_tween(actor)
    if tween.is_running():
        return Status.RUNNING
    return Status.SUCCESS

func _init_tween(actor: Node):
    if tween == null:
        tween = get_tree().create_tween().bind_node(actor)
        tween.set_trans(transition_type)
        tween.set_ease(ease_type)
        tween.tween_property(actor, tween_property, tween_value, duration)
ThePat02 commented 10 months ago

One Leaf for each value seems pretty overkill. You could probably export a Script resource that is responsible for creating the tween. If you can come up with something, feel free to open a PR. I may look into it tomorrow and give it a try :)

ThePat02 commented 10 months ago

@squk Would you mind checking out #28? I added it as one node. Are there any other features that might be useful for this Leaf? (Types, callback, tween method etc.)

squk commented 10 months ago

LGTM! Much better than the impl I provided