80 lines
1.7 KiB
GDScript3
80 lines
1.7 KiB
GDScript3
|
extends ActionLeaf
|
||
|
#当前是否已经开始运动
|
||
|
var is_started_self:bool=false
|
||
|
@export var time_out_time:float=2
|
||
|
var is_time_out:bool=false
|
||
|
@onready var timer: Timer = $Timer
|
||
|
|
||
|
func tick(actor:Node,black_board:Blackboard):
|
||
|
var unit:Unit=actor
|
||
|
if not is_started_self:
|
||
|
if not black_board.has_value("run_pos"):
|
||
|
return FAILURE
|
||
|
var run_pos:Vector2=black_board.get_value("run_pos")
|
||
|
actor.set_target_pos(run_pos)
|
||
|
is_started_self=true
|
||
|
timer.start(time_out_time)
|
||
|
match unit.get_dir():
|
||
|
0:
|
||
|
unit.play_animation("up")
|
||
|
1:
|
||
|
unit.play_animation("down")
|
||
|
2:
|
||
|
unit.play_animation("left_right")
|
||
|
3:
|
||
|
unit.play_animation("left_right")
|
||
|
return RUNNING
|
||
|
|
||
|
else:
|
||
|
if is_time_out:
|
||
|
is_started_self=false
|
||
|
black_board.erase_value("run_pos")
|
||
|
is_time_out=false
|
||
|
timer.stop()
|
||
|
unit.stop_move()
|
||
|
match unit.get_dir():
|
||
|
0:
|
||
|
unit.play_animation("up_idle")
|
||
|
1:
|
||
|
unit.play_animation("down_idle")
|
||
|
2:
|
||
|
unit.play_animation("left_right_idle")
|
||
|
3:
|
||
|
unit.play_animation("left_right_idle")
|
||
|
return FAILURE
|
||
|
|
||
|
if actor.is_move_finished():
|
||
|
is_started_self=false
|
||
|
black_board.erase_value("run_pos")
|
||
|
is_time_out=false
|
||
|
timer.stop()
|
||
|
match unit.get_dir():
|
||
|
0:
|
||
|
unit.play_animation("up_idle")
|
||
|
1:
|
||
|
unit.play_animation("down_idle")
|
||
|
2:
|
||
|
unit.play_animation("left_right_idle")
|
||
|
3:
|
||
|
unit.play_animation("left_right_idle")
|
||
|
return SUCCESS
|
||
|
else:
|
||
|
match unit.get_dir():
|
||
|
0:
|
||
|
unit.play_animation("up")
|
||
|
1:
|
||
|
unit.play_animation("down")
|
||
|
2:
|
||
|
unit.play_animation("left_right")
|
||
|
3:
|
||
|
unit.play_animation("left_right")
|
||
|
return RUNNING
|
||
|
|
||
|
|
||
|
pass
|
||
|
|
||
|
|
||
|
func _on_timer_timeout() -> void:
|
||
|
is_time_out=true
|
||
|
pass # Replace with function body.
|