extends Node3D @export var broken_object : Resource @export var break_velocity : float = 10 var can_break : bool = true var break_on_land : bool = false var held_currently : bool = false @onready var collision_shape_3d: CollisionShape3D = $CollisionShape3D @onready var breaking_sound: AudioStreamPlayer3D = $BreakingSound # Called when the node enters the scene tree for the first time. func _ready(): pass # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): pass func breaking(current_velocity): breaking_sound.play() 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) visible = false await get_tree().create_timer(.5).timeout queue_free() func _on_area_3d_body_entered(body: Node3D) -> void: if can_break: if body.is_in_group("player") and body.crouched and body.velocity.length() > 5: if HelperFuncs.angle_velocity_aligned(self,Vector3(0,0,1),body,Vector3(.2,1,.2)): collision_shape_3d.disabled = true can_break = false breaking(body.velocity) func save(): var save_dict = { "filename" : get_scene_file_path(), "parent" : get_parent().get_path(), "pos_x" : position.x, "pos_y" : position.y, "pos_z" : position.z, "rot_x" : rotation.x, "rot_y" : rotation.y, "rot_z" : rotation.z, } return save_dict