extends Projectile @export var explosion : Resource @export var blast_radius_area : Node @export var radius_shape : Node @export var blast_radius_falloff : Resource # Called when the node enters the scene tree for the first time. func _ready(): blast_radius = radius_shape.shape.radius func _on_body_shape_entered(body_rid, body, body_shape_index, local_shape_index): #move objects explode() #Spawn gpu particles var explosionspawn = explosion.instantiate() explosionspawn.position = self.global_position explosionspawn.transform.basis = self.global_transform.basis get_tree().get_root().add_child(explosionspawn) queue_free() func explode(): #get all collision objects that can be moved var bodies_in_blast = blast_radius_area.get_overlapping_bodies() #for each object determine vector from center of blast radius #apply linear velocity power as the inverse % of distance towards the edge (bonus points if using curve texture) #break breakable objects for body in bodies_in_blast: #calculate blast power and direction var blast_direction = (body.global_position - blast_radius_area.global_position).normalized() var blast_amount = 1 - ((body.global_position - blast_radius_area.global_position).length() / blast_radius) var blast_velocity = blast_direction * blast_power * blast_amount #apply and/or damage if body.get_class() == "RigidBody3D": if body.has_method("breaking"): body.breaking(blast_velocity) else: body.linear_velocity += blast_velocity if body.is_in_group("player"): body.velocity += clamp(blast_velocity,Vector3(-7,-7,-7),Vector3(7,7,7)) body.recoil.add_recoil(Vector3(1,.1,.1),10,10) if body.has_method("hit") and !body.is_in_group("player"): body.hit(1) if body.is_in_group("enemy"): if body.has_method("stun"): body.stun()