44 lines
862 B
GDScript
44 lines
862 B
GDScript
class_name Ghost
|
|
extends Node3D
|
|
|
|
static var _models: Array[PackedScene] = [
|
|
load("res://assets/ghost1.glb"),
|
|
load("res://assets/ghost2.glb"),
|
|
load("res://assets/ghost3.glb"),
|
|
]
|
|
|
|
var _rise_speed := 0.0
|
|
var _turn_speed := 0.0
|
|
var _fall_velocity := 0.0
|
|
|
|
var is_crushed := false
|
|
|
|
|
|
func _ready() -> void:
|
|
add_child(_models.pick_random().instantiate())
|
|
_rise_speed = randf_range(0.06, 0.1)
|
|
_turn_speed = randf_range(0.06, 0.2) * [1, -1].pick_random()
|
|
|
|
|
|
func _physics_process(_delta: float) -> void:
|
|
if not is_crushed:
|
|
position.y += _rise_speed
|
|
rotate_y(_turn_speed)
|
|
else:
|
|
_fall_velocity += -0.002
|
|
position.y += _fall_velocity
|
|
|
|
|
|
func crush(final_position_x: float) -> void:
|
|
is_crushed = true
|
|
|
|
position.x = final_position_x
|
|
rotation.y = 0
|
|
scale.x = 0.2
|
|
scale.y = 1.4
|
|
reset_physics_interpolation()
|
|
|
|
|
|
func _on_screen_exited() -> void:
|
|
queue_free()
|