40 lines
1.1 KiB
GDScript3
Raw Normal View History

extends "res://Scripts/animationBase.gd"
2024-05-03 19:45:30 -04:00
var path: PathFollow2D
var failPath: PathFollow2D
var casting: bool = true
var timer: float = 0
@onready var texture: TextureRect = $Path2D/PathFollow2D/TextureRect
# Called when the node enters the scene tree for the first time.
func _ready():
2024-05-03 19:45:30 -04:00
if !inverted:
path = $Path2D/PathFollow2D
failPath = $Path2D/PathFollow2D/Path2D/PathFollow2D
else:
path = $Path2D/PathFollow2D
failPath = $Path2D/PathFollow2D/Path2D/PathFollow2D
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
2024-05-03 19:45:30 -04:00
if casting:
if targetProg / finalProg < 0.7:
timer = clampf(timer + delta, 0, clampf(targetProg / finalProg, 0, 0.35))
path.progress_ratio = timer
else:
timer = clampf(timer + delta, 0, 1)
path.progress_ratio = timer
2024-05-03 19:45:30 -04:00
if path.progress_ratio == 1:
self.free()
else:
timer = clampf(timer + (1.25 * delta), 0, 1)
failPath.progress_ratio = timer
if failPath.progress_ratio == 1:
self.free()
func castFailed() -> void:
2024-05-03 19:45:30 -04:00
casting = false
texture.get_parent().remove_child(texture)
failPath.add_child(texture)
timer = 0