otherworldly_simulation/scene/test/action_set_rand_pos.gd
2024-10-25 15:41:39 +08:00

20 lines
641 B
GDScript

extends ActionLeaf
##随机进行的距离最大值
@export var rand_length_max:float=100
##随机进行的距离最小值
@export var rand_length_min:float=50
func tick(actor:Node,black_board:Blackboard):
var unit:Unit=actor
if unit.get_hungry()>50:
rand_length_max=float(unit.get_hungry()-50)/50*2000
else:
rand_length_max=100
var now_pos=actor.global_position
#随机距离
var rand_distance=randf_range(rand_length_min,rand_length_max)
#随机方向
var rand_dir:Vector2=Vector2(2*randf()-1,2*randf()-1).normalized()
var target_pos=now_pos+rand_dir*rand_distance
black_board.set_value("run_pos",target_pos)
return SUCCESS