27 lines
683 B
GDScript
27 lines
683 B
GDScript
extends ActionLeaf
|
|
|
|
func tick(actor: Node, blackboard: Blackboard) -> int:
|
|
# Get target from blackboard
|
|
var target_pos = blackboard.get_value("move_target")
|
|
if not target_pos:
|
|
return FAILURE
|
|
|
|
if actor.action_points <= 0:
|
|
return FAILURE
|
|
|
|
# Execute movement
|
|
if actor.is_within_movement_range(target_pos):
|
|
if actor.is_multiplayer_authority():
|
|
var path = actor.enhanced_gridmap.find_path(
|
|
Vector2(actor.current_position),
|
|
Vector2(target_pos)
|
|
)
|
|
if path.size() > 1:
|
|
path.pop_front()
|
|
actor.rpc("start_movement_along_path", path)
|
|
actor.action_points -= 1
|
|
blackboard.set_value("current_action", "moving")
|
|
return SUCCESS
|
|
|
|
return FAILURE
|