Files
fps_project_1/scripts/breakable.gd
2024-11-04 23:04:56 -06:00

33 lines
937 B
GDScript

extends RigidBody3D
@export var broken_object : Resource
var break_on_land : bool = 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):
if linear_velocity.length() >= 10:
break_on_land = true
func breaking(current_velocity):
var spawn_broken = broken_object.instantiate()
spawn_broken.position = global_position
spawn_broken.transform.basis = global_transform.basis
spawn_broken.rotation = rotation
var pieces = spawn_broken.get_children()
for piece in pieces:
if piece is RigidBody3D:
piece.linear_velocity += current_velocity
get_tree().get_root().add_child(spawn_broken)
queue_free()
func _on_body_shape_entered(body_rid: RID, body: Node, body_shape_index: int, local_shape_index: int) -> void:
if break_on_land:
breaking(linear_velocity)