76 lines
1.8 KiB
GDScript
76 lines
1.8 KiB
GDScript
extends StaticBody3D
|
|
|
|
# Exports
|
|
@export_category('Commentary')
|
|
|
|
@export_subgroup('Sound')
|
|
@export
|
|
var sound: AudioStream = null :
|
|
get:
|
|
return $AudioStreamPlayer3D.stream
|
|
set(value):
|
|
$AudioStreamPlayer3D.stream = value
|
|
|
|
@export_range(-80, 80, 1, "suffix:dB")
|
|
var volume = 0.0 :
|
|
get:
|
|
return $AudioStreamPlayer3D.volume_db
|
|
set(value):
|
|
$AudioStreamPlayer3D.volume_db = value
|
|
|
|
@export_subgroup('Range')
|
|
@export_range(0, 100, 1, "suffix:m")
|
|
var capture_radius = 10.0
|
|
@export_range(0, 100, 1, "suffix:mad/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():
|
|
$AudioStreamPlayer3D.stream = sound
|
|
$AudioStreamPlayer3D.volume_db = volume
|
|
$AudioStreamPlayer3D.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 $AudioStreamPlayer3D.playing:
|
|
return
|
|
|
|
_original_color = $Koob.material.albedo_color
|
|
|
|
var random_color = Color(randf(), randf(), randf())
|
|
$Koob.material.albedo_color = random_color
|
|
|
|
$AudioStreamPlayer3D.play()
|
|
|
|
|
|
func _on_finished_playing():
|
|
if _original_color:
|
|
$Koob.material.albedo_color = _original_color
|