Jam10/Scripts/Units/FollowReplay.gd

30 lines
704 B
GDScript

extends Unit
var replay : ReplayRecording = null
export var replay_file: String
func _ready():
._ready()
replay = ReplayRecording.new()
replay.load_from_uri(replay_file)
func process_unit(delta : float, time_elapsed : float):
self.time_elapsed = time_elapsed
if replay != null and replay.time_per_frame > 0:
handle_replay(time_elapsed)
func handle_replay(at_time: float):
var frame: int = int(at_time / replay.time_per_frame)
var subframe: float = (at_time / replay.time_per_frame) - frame
pos = lerp(replay.position(frame), replay.position(frame + 1), subframe)
var sprite: int = replay.sprite(frame)
var index: int = sprite >> 3
sprite &= 7
set_sprite(sprite, index, true)