rocket pull radius of collision shape for blast radius

This commit is contained in:
derek
2024-08-01 11:33:15 -05:00
parent b1c92e5d2c
commit e4129d7fb7
3 changed files with 26 additions and 18 deletions

View File

@@ -64,7 +64,7 @@ height = 1.21279
[sub_resource type="SphereShape3D" id="SphereShape3D_vdo7n"]
radius = 10.0
[node name="Rocket" type="RigidBody3D" node_paths=PackedStringArray("blast_radius")]
[node name="Rocket" type="RigidBody3D" node_paths=PackedStringArray("blast_radius_area", "radius_shape")]
collision_layer = 6
collision_mask = 7
continuous_cd = true
@@ -72,7 +72,8 @@ max_contacts_reported = 100
contact_monitor = true
script = ExtResource("1_s0phn")
explosion = ExtResource("2_mbh48")
blast_radius = NodePath("BlastRadius")
blast_radius_area = NodePath("BlastRadius")
radius_shape = NodePath("BlastRadius/radiusShape")
blast_radius_falloff = SubResource("CurveTexture_0mibw")
[node name="Rocket" type="MeshInstance3D" parent="."]

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://6p7d7txcox7i"]
[gd_scene load_steps=9 format=3 uid="uid://6p7d7txcox7i"]
[ext_resource type="Script" path="res://scripts/die_particles.gd" id="1_ssw3i"]
[ext_resource type="AudioStream" uid="uid://wd061pl0d7rl" path="res://assets/Audio/deep-low-explosion-SBA-300054677.wav" id="5_awm3r"]
@@ -24,12 +24,15 @@ spread = 66.739
initial_velocity_min = 10.0
initial_velocity_max = 15.0
scale_min = 0.1
scale_max = 0.3
hue_variation_min = 0.1
hue_variation_max = 0.2
hue_variation_curve = SubResource("CurveTexture_7652j")
[sub_resource type="BoxMesh" id="BoxMesh_rsjsy"]
[sub_resource type="Skin" id="Skin_v2ayh"]
[node name="rocketexplosion" type="Node3D"]
script = ExtResource("1_ssw3i")
@@ -46,6 +49,7 @@ trail_enabled = true
trail_lifetime = 3.2
process_material = SubResource("ParticleProcessMaterial_evi0f")
draw_pass_1 = SubResource("BoxMesh_rsjsy")
draw_skin = SubResource("Skin_v2ayh")
[node name="Audio" type="Node3D" parent="."]

View File

@@ -1,11 +1,12 @@
extends RigidBody3D
@export var explosion : Resource
@export var blast_radius : Node
@export var blast_radius_area : Node
@export var radius_shape : Node
@export var blast_radius_falloff : Resource
@onready var radius_shape = $BlastRadius/radiusShape
var blast_power
var blast_radius
var bullet_speed
var player_velocity
var bullet_damage
@@ -14,7 +15,7 @@ var player_position
# Called when the node enters the scene tree for the first time.
func _ready():
linear_velocity += transform.basis * Vector3(0, 0, -bullet_speed) + player_velocity
blast_radius = radius_shape.shape.radius
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
@@ -22,26 +23,28 @@ func _process(delta):
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()
if !body.is_in_group("player"):
#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 moveable_rigidbodies = blast_radius.get_overlapping_bodies()
var moveable_rigidbodies = 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 moveable_rigidbodies:
if body.is_in_group("scene_rigidbody"):
var blast_direction = (body.global_position - blast_radius.global_position).normalized()
var blast_amount = 1 - ((body.global_position - blast_radius.global_position).length() / 10)
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
if body.is_in_group("breakable"):
body.breaking(blast_velocity)