bovido/scripts/enemy/behavior_tree/move_to_destination_action.gd

23 lines
793 B
GDScript3
Raw Normal View History

2023-06-13 21:36:01 +02:00
class_name MoveToDestinationAction
extends ActionLeaf
func before_run(actor, blackboard):
var destination = blackboard.get_value("destination")
actor.sprite.flip_h = actor.position.x > destination.x
actor.animation_player.play("walk")
func tick(actor: Node, blackboard: Blackboard):
var destination = blackboard.get_value("destination")
var delta = get_physics_process_delta_time()
actor.position = actor.position.move_toward(destination, delta * actor.speed)
if actor.position == destination:
return SUCCESS
return RUNNING
func after_run(actor, blackboard):
var destination = blackboard.get_value("destination")
destination.y -= actor.Y_SPAWN_OFFSET
var cell = actor.tile_map.local_to_map(destination)
actor.tile_map.set_cell(0, cell, 0, Vector2i(0, 0), 0) # debug purpose