cawez_puzzlebox/cubes/physics/follow_down.gd

43 lines
1.2 KiB
GDScript

extends RigidBody3D
var death_direction = Vector3(0,0,0)
var alpha = 0.3
@export var mesh : Array[Node3D]
@export var colliders : Array[CollisionShape3D]
@export var hotspot = false
@export var killable = false
# 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):
#apply_central_force(Globals.global_down * 9.8 * 1000 * delta * mass)
linear_velocity = Globals.global_down * 25.0
# Snaps to grid ( used in simulated levels )
if Globals.global_down.dot(Vector3.DOWN) > 0.9 && hotspot:
position = 3 * Vector3(round(position.x/3),position.y/3,round(position.z/3))
if killable:
# Killed
if death_direction != Vector3.ZERO:
# No longer moves!
linear_damp = INF
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