limboai/demo/demo/ai/tasks/face_target.gd

21 lines
569 B
GDScript

@tool
extends BTAction
## FaceTarget
@export var target_var: String = "target"
# Display a customized name (requires @tool).
func _generate_name() -> String:
return "FaceTarget " + LimboUtility.decorate_var(target_var)
# Called each time this task is ticked (aka executed).
func _tick(delta: float) -> Status:
var target := blackboard.get_var(target_var) as CharacterBody2D
if not is_instance_valid(target):
return FAILURE
var dir: float = target.global_position.x - agent.global_position.x
agent.velocity = Vector2.ZERO
agent.face_dir(dir)
return SUCCESS