otherworldly_simulation/scene/test/action_move_to_target.gd

65 lines
1.6 KiB
GDScript3
Raw Permalink Normal View History

2024-10-25 15:41:39 +08:00
extends ActionLeaf
#执行成功后是否抹除黑板目标数据
@export var should_erase_target:bool=false
#用于移动到特定单位的可交互范围内
func tick(actor:Node,black_board:Blackboard):
var unit:Unit=actor
if black_board.has_value("target"):
var target=black_board.get_value("target")
if not is_instance_valid(target) or not target is Node2D:
black_board.erase_value("target")
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")
unit.stop_move()
return FAILURE
#获取要移动到的目标
if unit.is_unit_instance_in_touch_area(target):
if should_erase_target:
black_board.erase_value("target")
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")
unit.stop_move()
return SUCCESS
unit.set_target_pos(target.global_position)
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:
black_board.erase_value("target")
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")
unit.stop_move()
return FAILURE