cawez_puzzlebox/cubes/tile/cube_tile.gd
2024-06-22 22:24:36 -04:00

56 lines
1.4 KiB
GDScript

extends RigidBody3D
@export var recursive = false
var buffer = Vector3(0,0,0)
@export var clear_buffer = true
var death_direction = Vector3(0,0,0)
@export var mesh : Array[Node3D]
@export var colliders : Array[CollisionShape3D]
var alpha = 0.3
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
# Killed
if death_direction != Vector3.ZERO:
for mesh_animation in mesh:
# Melts the mesh
mesh_animation.scale = mesh_animation.scale.lerp(Vector3(0,0,0), 1 - alpha ** delta)
# Absorbs
mesh_animation.global_position = mesh_animation.global_position.lerp(mesh_animation.global_position + death_direction, 1 - alpha ** delta)
for collider_animation in colliders:
collider_animation.disabled = true
if (buffer != Vector3.ZERO):
move(buffer)
if clear_buffer:
buffer = Vector3.ZERO
func move(direction) -> bool:
$raycast_wall.target_position = direction
$raycast_wall.force_raycast_update()
$raycast_recursive.target_position = direction
$raycast_recursive.force_raycast_update()
if !$raycast_wall.is_colliding():
translate(direction)
return true
if recursive && $raycast_recursive.is_colliding():
if ($raycast_recursive.get_collider().move(direction)):
translate(direction)
return true
return false