61 lines
1.4 KiB
GDScript
61 lines
1.4 KiB
GDScript
extends LimboState
|
|
|
|
@export_category("Hook Pull Release")
|
|
@export var release_distance: float = 12.0
|
|
@export var release_dot_threshold: float = 0.0
|
|
@export var min_pull_time: float = 0.08
|
|
|
|
var _pull_time := 0.0
|
|
var _anchor
|
|
|
|
func _enter() -> void:
|
|
_pull_time = 0.0
|
|
_anchor = agent.spawn_hook_comp.get_current_hook_anchor()
|
|
|
|
if _anchor and is_instance_valid(_anchor):
|
|
agent.locomotion_comp._custom_move_to(_anchor)
|
|
|
|
func _update(delta: float) -> void:
|
|
_pull_time += delta
|
|
|
|
if _pull_time < min_pull_time:
|
|
return
|
|
|
|
if not _anchor or not is_instance_valid(_anchor):
|
|
_force_release()
|
|
return
|
|
|
|
var character : CharacterBody2D = agent
|
|
var pos: Vector2 = character.global_position
|
|
var target_pos: Vector2 = _anchor.global_position
|
|
|
|
var to_target := target_pos - pos
|
|
var distance := to_target.length()
|
|
|
|
if distance <= release_distance:
|
|
_force_release()
|
|
return
|
|
|
|
if distance > 0.001:
|
|
var dir := to_target / distance
|
|
if character.velocity.dot(dir) <= release_dot_threshold:
|
|
_force_release()
|
|
return
|
|
|
|
func _exit() -> void:
|
|
agent.locomotion_comp.stop_custom_move(false)
|
|
_anchor = null
|
|
|
|
func _force_release() -> void:
|
|
agent.locomotion_comp.stop_custom_move(false)
|
|
|
|
if agent.spawn_hook_comp.has_method("release_hook"):
|
|
agent.spawn_hook_comp.release_hook()
|
|
|
|
##解除hook
|
|
if agent.is_on_floor():
|
|
self.dispatch(&"exit_on_ground")
|
|
else:
|
|
self.dispatch(&"exit_on_air")
|
|
return
|