more tweaks to breakable vent and barrel can now explode
This commit is contained in:
@@ -17,6 +17,7 @@ func _process(delta):
|
||||
|
||||
func hit(bullet_damage):
|
||||
emit_signal("body_part_hit", damage, bullet_damage)
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
|
||||
var number_spawn = damage_number.instantiate()
|
||||
number_spawn.damage_amt = bullet_damage * damage
|
||||
|
||||
@@ -5,17 +5,10 @@ extends Node
|
||||
# Check if a colliding body is aligned within a given angle of the object
|
||||
# max_angle_diff --- note: set to 1 if angle won't be counted
|
||||
# currently only works when objects are scaled (1,1,1)
|
||||
func angle_velocity_aligned(source:Node,source_angle:Vector3,body:Node,max_angle_diff:Vector3):
|
||||
func angle_velocity_aligned(source:Node, source_angle:Vector3, body:Node, max_angle_diff:Vector3):
|
||||
var obj_direction = source.basis * source_angle
|
||||
print("SOURCE BASIS ",source.basis)
|
||||
var player_direction = body.velocity.normalized()
|
||||
var diff = abs(abs(obj_direction) - abs(player_direction))
|
||||
print("------------------------------------------------------------")
|
||||
print("OBJ DIRECTION: ",obj_direction)
|
||||
print("PLAYER DIRECTION: ", player_direction)
|
||||
print("MAX ANGLE DIFF ",max_angle_diff)
|
||||
print("DIFFERENCE: ", diff)
|
||||
print("------------------------------------------------------------")
|
||||
if diff.x <= max_angle_diff.x and diff.y <= max_angle_diff.y and diff.z <= max_angle_diff.z:
|
||||
return true
|
||||
else:
|
||||
|
||||
@@ -41,10 +41,9 @@ func _physics_process(delta):
|
||||
mesh.visible = false
|
||||
ray.enabled = false
|
||||
|
||||
if body.is_in_group("enemy_target"):
|
||||
if body.has_method("hit"):
|
||||
hit_indicator.play()
|
||||
enemy_particles.emitting = true
|
||||
SignalBus.emit_signal("enemy_hit")
|
||||
ray.get_collider().hit(bullet_damage)
|
||||
|
||||
#bullethole effect
|
||||
|
||||
88
scripts/oildrum.gd
Normal file
88
scripts/oildrum.gd
Normal file
@@ -0,0 +1,88 @@
|
||||
extends RigidBody3D
|
||||
|
||||
@export var hp : float = 3
|
||||
@export var explosion : Resource
|
||||
@export var blast_power : float = 10
|
||||
@export_enum("Enemy", "Trap") var enemy_type: int
|
||||
|
||||
@onready var leak_audio: AudioStreamPlayer3D = $leak_audio
|
||||
@onready var blast_radius_area: Area3D = $BlastRadius
|
||||
@onready var radius_shape: CollisionShape3D = $BlastRadius/CollisionShape3D
|
||||
|
||||
var leak_hp = false
|
||||
var blast_amount
|
||||
|
||||
const HP_LEAK_RATE = .5
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
add_to_group("persist")
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
if leak_hp:
|
||||
hp -= delta * HP_LEAK_RATE
|
||||
print("HP - ",hp)
|
||||
if hp <= 0:
|
||||
explode()
|
||||
|
||||
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,
|
||||
"hp" : hp,
|
||||
"leak_hp" : leak_hp,
|
||||
}
|
||||
return save_dict
|
||||
|
||||
func hit(bullet_damage):
|
||||
hp -= 1
|
||||
leak_hp = true
|
||||
leak_audio.play()
|
||||
|
||||
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() / radius_shape.shape.radius)
|
||||
var blast_velocity = blast_direction * blast_power * blast_amount
|
||||
|
||||
#apply and/or damage
|
||||
if body.get_class() == "RigidBody3D":
|
||||
if body.is_in_group("breakable"):
|
||||
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)
|
||||
body.hit(1,self,enemy_type)
|
||||
if body.has_method("hit") and !body.is_in_group("player"):
|
||||
body.hit(1)
|
||||
if body.is_in_group("enemy"):
|
||||
body.knocked = true
|
||||
body.stunned = true
|
||||
print("knocked")
|
||||
body.knocked_timer.start()
|
||||
body.stunned_timer.start()
|
||||
body.velocity += blast_velocity
|
||||
|
||||
#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()
|
||||
@@ -48,8 +48,8 @@ func explode():
|
||||
var blast_velocity = blast_direction * blast_power * blast_amount
|
||||
|
||||
#apply and/or damage
|
||||
if body.is_in_group("scene_rigidbody"):
|
||||
if body.is_in_group("breakable"):
|
||||
if body.get_class() == "RigidBody3D":
|
||||
if body.has_method("breaking"):
|
||||
body.breaking(blast_velocity)
|
||||
else:
|
||||
body.linear_velocity += blast_velocity
|
||||
|
||||
Reference in New Issue
Block a user