41 lines
1.0 KiB
GDScript3
41 lines
1.0 KiB
GDScript3
|
class_name Springboard extends Area3D
|
||
|
|
||
|
const BASE_ANIM_SPEED: float = 5.0
|
||
|
|
||
|
@export var launch_speed: float = 30.0
|
||
|
|
||
|
@onready var mesh := $'Mesh' as MeshInstance3D
|
||
|
@onready var audio_player := $'AudioStreamPlayer' as AudioStreamPlayer
|
||
|
var boing: int
|
||
|
var anim_progress: float = -1.0
|
||
|
|
||
|
func _ready() -> void:
|
||
|
boing = mesh.find_blend_shape_by_name(&'Boing')
|
||
|
body_entered.connect(propel)
|
||
|
mesh.set_instance_shader_parameter(
|
||
|
&'hue_shift',
|
||
|
launch_speed - 30.0
|
||
|
)
|
||
|
|
||
|
func propel(body: PhysicsBody3D) -> void:
|
||
|
if body is RigidBody3D:
|
||
|
if body is Runner:
|
||
|
var runner := body as Runner
|
||
|
runner.change_state(&'jump')
|
||
|
runner.up_normal = basis.y
|
||
|
audio_player.play()
|
||
|
anim_progress = 0.0
|
||
|
(body as RigidBody3D).linear_velocity = launch_speed*basis.y
|
||
|
|
||
|
|
||
|
func _process(delta: float) -> void:
|
||
|
if anim_progress >= 0.0:
|
||
|
anim_progress += delta*BASE_ANIM_SPEED
|
||
|
if anim_progress < 1.0:
|
||
|
mesh.set_blend_shape_value(
|
||
|
boing, clampf(1.0 - 2.0*abs(anim_progress - 0.5), 0.0, 1.0)
|
||
|
)
|
||
|
else:
|
||
|
mesh.set_blend_shape_value(boing, 0.0)
|
||
|
anim_progress = -1.0
|