17 lines
712 B
GDScript
17 lines
712 B
GDScript
extends BehaviourAction
|
|
|
|
@export var target_distance : float = 1.2
|
|
|
|
@onready var body := get_behaviour_tree().get_parent() as CharacterBody3D
|
|
@onready var anim := get_behaviour_tree().get_node("%AnimationPlayer") as AnimationPlayer
|
|
|
|
func _enter() -> int:
|
|
if body.target == null or body.target.global_position.distance_to(body.global_position) > target_distance:
|
|
var difference : Vector3 = body.global_position - body.target.global_position
|
|
var z_basis : Vector3 = body.global_basis.z
|
|
var full_angle := Vector3(z_basis.x, 0, z_basis.z).signed_angle_to(Vector3(difference.x, 0, difference.z).normalized(), Vector3.UP)
|
|
body.rotate_y(full_angle)
|
|
anim.play("run", .1)
|
|
return Fail
|
|
else:
|
|
return Success
|