forked from funnymemellama/funnymemellama
83 lines
1.8 KiB
GDScript
83 lines
1.8 KiB
GDScript
extends StaticBody3D
|
|
|
|
|
|
@onready
|
|
var _audio = $AudioStreamPlayer
|
|
@onready
|
|
var _koob = $Koob
|
|
|
|
|
|
# Exports
|
|
@export_category('Commentary')
|
|
|
|
@export_subgroup('Sound')
|
|
@export
|
|
var sound: AudioStream = null :
|
|
get:
|
|
return $AudioStreamPlayer.stream
|
|
set(value):
|
|
$AudioStreamPlayer.stream = value
|
|
|
|
@export_range(-80, 80, 1, "suffix:dB")
|
|
var volume = 0.0 :
|
|
get:
|
|
return $AudioStreamPlayer.volume_db
|
|
set(value):
|
|
$AudioStreamPlayer.volume_db = value
|
|
|
|
@export_subgroup('Range')
|
|
@export_range(0, 100, 1, "suffix:m")
|
|
var capture_radius = 10.0
|
|
@export_range(0, 100, 1, "suffix:rad/s")
|
|
var low_speed = 1.0
|
|
@export_range(0, 100, 1, "suffix:rad/s")
|
|
var high_speed = 10.0
|
|
@export
|
|
var pre = 1.0
|
|
@export
|
|
var post = 1.0
|
|
|
|
# Member variables
|
|
var _original_color = null
|
|
|
|
|
|
func _ready():
|
|
_audio.stream = sound
|
|
_audio.volume_db = volume
|
|
_audio.finished.connect(_on_finished_playing)
|
|
|
|
# Make sure we have a unique material
|
|
# TODO: Why the fuck do I have to do this!?
|
|
# Isn't that the whole point of the "Make Unique"
|
|
_koob.material = _koob.material.duplicate()
|
|
|
|
|
|
func _process(delta):
|
|
var players = get_tree().get_nodes_in_group("Players")
|
|
|
|
var shortest_distance = capture_radius
|
|
for player in players:
|
|
var player_dist = self.position.distance_to(player.position)
|
|
shortest_distance = min(shortest_distance, player_dist)
|
|
|
|
var weight = (capture_radius - shortest_distance) / capture_radius
|
|
var spin_speed = cubic_interpolate(low_speed, high_speed, pre, post, weight)
|
|
|
|
self.rotate_y(spin_speed * delta)
|
|
|
|
|
|
func interact(other):
|
|
if _audio.playing:
|
|
return
|
|
|
|
_original_color = _koob.material.albedo_color
|
|
|
|
var random_color = Color(randf(), randf(), randf())
|
|
_koob.material.albedo_color = random_color
|
|
|
|
_audio.play()
|
|
|
|
|
|
func _on_finished_playing():
|
|
if _original_color:
|
|
_koob.material.albedo_color = _original_color
|