2023-07-21 09:50:06 +00:00
|
|
|
#*
|
|
|
|
#* arrive_pos.gd
|
|
|
|
#* =============================================================================
|
|
|
|
#* Copyright 2021-2023 Serhii Snitsaruk
|
|
|
|
#*
|
|
|
|
#* Use of this source code is governed by an MIT-style
|
|
|
|
#* license that can be found in the LICENSE file or at
|
|
|
|
#* https://opensource.org/licenses/MIT.
|
|
|
|
#* =============================================================================
|
|
|
|
#*
|
|
|
|
|
2022-12-15 13:49:38 +00:00
|
|
|
@tool
|
|
|
|
@icon("res://icon.png")
|
2023-04-16 06:26:47 +00:00
|
|
|
class_name ArrivePos
|
2023-03-02 14:41:01 +00:00
|
|
|
extends BTAction
|
2022-12-15 13:49:38 +00:00
|
|
|
|
|
|
|
@export var target_position_var := "target_position"
|
|
|
|
@export var speed_var := "speed"
|
|
|
|
@export var tolerance := 50.0
|
|
|
|
|
|
|
|
|
|
|
|
func _generate_name() -> String:
|
|
|
|
return "Arrive pos: %s speed: %s" % [
|
|
|
|
LimboUtility.decorate_var(target_position_var),
|
|
|
|
LimboUtility.decorate_var(speed_var),
|
|
|
|
]
|
|
|
|
|
2023-09-19 11:53:01 +00:00
|
|
|
func _tick(p_delta: float) -> Status:
|
2022-12-15 13:49:38 +00:00
|
|
|
var target_pos: Vector2 = blackboard.get_var(target_position_var, Vector2.ZERO)
|
|
|
|
if target_pos.distance_to(agent.global_position) < tolerance:
|
|
|
|
return SUCCESS
|
2023-04-14 08:28:33 +00:00
|
|
|
|
2022-12-15 13:49:38 +00:00
|
|
|
var speed: float = blackboard.get_var(speed_var, 10.0)
|
|
|
|
var dir: Vector2 = agent.global_position.direction_to(target_pos)
|
|
|
|
agent.global_position += dir * speed * p_delta
|
|
|
|
return RUNNING
|