added breakable vent
This commit is contained in:
22
scripts/HelperFuncs.gd
Normal file
22
scripts/HelperFuncs.gd
Normal file
@@ -0,0 +1,22 @@
|
||||
extends Node
|
||||
|
||||
## ANGLES
|
||||
|
||||
# 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):
|
||||
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:
|
||||
return false
|
||||
@@ -383,7 +383,7 @@ func _physics_process(delta):
|
||||
else:
|
||||
moveable_holder.rotation.y -= deg_to_rad(45)
|
||||
|
||||
for i in range(10):
|
||||
for i in range(1,9):
|
||||
if Input.is_action_just_pressed("numb_" + str(i)):
|
||||
if gun != null:
|
||||
if !gun.anim_player.is_playing():
|
||||
|
||||
@@ -6,7 +6,6 @@ extends Node3D
|
||||
@export var taunts : Array[String] = []
|
||||
|
||||
@onready var outline_meshes = [$Spikes1/MeshInstance3D]
|
||||
@onready var ray_cast: RayCast3D = $RayCast3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
@@ -20,5 +19,7 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_area_3d_body_entered(body: Node3D) -> void:
|
||||
if body.is_in_group("player"):
|
||||
body.hit(damage,self,enemy_type)
|
||||
body.velocity = ray_cast.global_transform.basis * Vector3(0,0,-pushback)
|
||||
if HelperFuncs.angle_velocity_aligned(self,Vector3(0,-1,0),body,Vector3(.7,.7,.7)):
|
||||
body.hit(damage,self,enemy_type)
|
||||
var bounce_velocity = -body.velocity
|
||||
body.velocity = bounce_velocity
|
||||
|
||||
56
scripts/vent_1.gd
Normal file
56
scripts/vent_1.gd
Normal file
@@ -0,0 +1,56 @@
|
||||
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
|
||||
Reference in New Issue
Block a user