35 lines
1,006 B
GDScript
35 lines
1,006 B
GDScript
extends RigidBody2D
|
|
|
|
|
|
@export var scale_min: float
|
|
@export var scale_max: float
|
|
@export var velocity_min: float
|
|
@export var velocity_max: float
|
|
@export_custom(0, "radians_as_degrees") var spin_min: float
|
|
@export_custom(0, "radians_as_degrees") var spin_max: float
|
|
@export var decay_speed_threshold: float
|
|
@export var decay_time: float
|
|
|
|
|
|
var _tween: Tween = null
|
|
|
|
|
|
func _ready() -> void:
|
|
var rnd_scale = randf_range(scale_min, scale_max)
|
|
$Sprite2D.scale = Vector2.ONE * rnd_scale
|
|
|
|
linear_velocity = Vector2.from_angle(randf() * TAU) * randf_range(velocity_min, velocity_max)
|
|
angular_velocity = randf_range(spin_min, spin_max)
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
if linear_velocity.length() <= decay_speed_threshold:
|
|
if _tween:
|
|
return
|
|
_tween = create_tween().set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
|
|
_tween.tween_property(self, ^"scale", Vector2.ZERO, decay_time)
|
|
_tween.tween_callback(queue_free)
|
|
|
|
|
|
func _on_solid_detector_body_entered(body: Node2D) -> void:
|
|
print("BLEP")
|