more various tweaks to held items and chests in order to make carrying chests fun

This commit is contained in:
derek
2025-03-04 17:02:52 -06:00
parent e84aea9ef7
commit 5d989470a6
20 changed files with 111 additions and 106 deletions

View File

@@ -25,6 +25,9 @@ func _on_area_3d_body_entered(body):
if body.is_in_group("player"):
can_jump = true
player = body
if body.is_class("Chest"):
body.velocity.y = jump_amount
jump_sound.play()
func _on_area_3d_body_exited(body: Node3D) -> void:
if body.is_in_group("player"):

View File

@@ -1,6 +1,7 @@
extends RayCast3D
@onready var hit_indicator: AudioStreamPlayer = $"../../../../Audio/HitIndicator"
@onready var camera: Camera3D = $".."
# Called when the node enters the scene tree for the first time.
@@ -12,31 +13,32 @@ func _ready() -> void:
func _process(delta: float) -> void:
pass
func hitscan_fire(bullet_damage,bullet_force_mod,bullethole):
func hitscan_fire(bullet_damage,bullet_force_mod,bullethole,range):
if is_colliding():
#bullethole effect
var instance_bullethole = bullethole.instantiate()
get_collider().add_child(instance_bullethole)
instance_bullethole.global_transform.origin = get_collision_point()
if (abs(get_collision_normal().y) > 0.99):
instance_bullethole.look_at(get_collision_point() + get_collision_normal(), Vector3(0,0,1))
else:
instance_bullethole.look_at(get_collision_point() + get_collision_normal())
#move rigidbodies
if get_collider().is_in_group("scene_rigidbody"):
get_collider().linear_velocity += rotation * Vector3(0,0,-bullet_force_mod)
if get_collider().is_in_group("breakable"):
get_collider().breaking( Vector3(0,0,-bullet_force_mod))
if camera.distance_to(get_collision_point) <= range:
#bullethole effect
var instance_bullethole = bullethole.instantiate()
get_collider().add_child(instance_bullethole)
instance_bullethole.global_transform.origin = get_collision_point()
if (abs(get_collision_normal().y) > 0.99):
instance_bullethole.look_at(get_collision_point() + get_collision_normal(), Vector3(0,0,1))
else:
instance_bullethole.look_at(get_collision_point() + get_collision_normal())
#move rigidbodies
if get_collider().is_in_group("scene_rigidbody"):
get_collider().linear_velocity += rotation * Vector3(0,0,-bullet_force_mod)
if get_collider().is_in_group("breakable"):
get_collider().breaking( Vector3(0,0,-bullet_force_mod))
if get_collider().is_in_group("enemy_target"):
emit_signal("enemy_hit")
get_collider().hit(bullet_damage)
if get_collider().is_in_group("switch"):
get_collider().hit()
if get_collider().is_in_group("enemy_target"):
emit_signal("enemy_hit")
get_collider().hit(bullet_damage)
if get_collider().is_in_group("switch"):
get_collider().hit()

View File

@@ -31,7 +31,7 @@ func _on_timer_timeout():
timer.wait_time = rand_timer #rand_timer
# Shoot that shit
var pickup_spawn = level_control.item_pickup.instantiate()
var pickup_spawn = level_control.ITEM_PICKUP.instantiate()
var item_stats = level_control.pickup_spawn(false)
##SET VARIABLES
pickup_spawn.pickup_type = item_stats["pickup_type"]

View File

@@ -1,6 +1,8 @@
extends RigidBody3D
class_name Chest
@export var weapon_drops : Array[Resource]
@export var health : float = 30
var open = false
var drop_weapon
@@ -19,7 +21,8 @@ func _process(delta: float) -> void:
pass
func hit(dam):
if !open:
health -= dam
if !open and health <= 0:
anim_player.play("open")
open = true
@@ -31,4 +34,4 @@ func spawn_drop():
get_tree().current_scene.add_child(drop_weapon)
func interact():
hit(0)
hit(1)

View File

@@ -86,6 +86,7 @@ var current_weapon_index
var recoiling = false
var dead = false
var hud_visible : bool = true
var held_item : Node
var held_item_linear_damp_cache
var held_item_angular_damp_cache
@@ -93,7 +94,8 @@ var held_item_gravity_cache
var held_item_mass_cache
var held_item_collision_cache
var hold_offset
var held_item_rotation = Vector3(0,0,0)
var held_item_rotation : float = 0
var gamespeed_controlled = false
var crouched = false
var flashlight_on : bool = false
@@ -137,7 +139,6 @@ var controlled_elsewhere = false
@onready var weapon_pickup_audio: AudioStreamPlayer = $Audio/WeaponPickup
@onready var motion_lines: ColorRect = $Head/Recoil/Camera3D/MotionLines
@onready var moveable_holder: Node3D = $Head/Recoil/Camera3D/MoveableHolder
@onready var moveable_rotation: Node3D = $Head/Recoil/Camera3D/MoveableHolder/MoveableRotation
@onready var stand_check: RayCast3D = $StandCheck
@onready var r_hand_test: MeshInstance3D = $Head/Recoil/Camera3D/WeaponHolder/RHandTest
@onready var enemy_killed_audio: AudioStreamPlayer = $Audio/EnemyKilled
@@ -405,13 +406,14 @@ func _physics_process(delta):
#Weapon Swap Up
if Input.is_action_just_pressed("scroll_up"):
if held_item != null:
held_item_rotation += deg_to_rad(45)
print("HELD ITEM ROTATION : ",held_item_rotation)
if gun != null:
if !gun.anim_player.is_playing():
if held_item == null:
if GameGlobals.held_guns.size() > 1:
weapon_select(GameGlobals.current_gun_index + 1)
else:
moveable_holder.rotation.y += deg_to_rad(45)
else:
if gun_is_holstered:
holster_gun(false)
@@ -424,7 +426,7 @@ func _physics_process(delta):
if GameGlobals.held_guns.size() > 1:
weapon_select(GameGlobals.current_gun_index - 1)
else:
moveable_holder.rotation.y -= deg_to_rad(45)
held_item_rotation -= deg_to_rad(45)
else:
if gun_is_holstered:
holster_gun(false)
@@ -461,6 +463,12 @@ func _physics_process(delta):
held_key_check += delta
## IF HELD
if held_key_check >= HELD_BUTTON_AMT:
if interact_ray.is_colliding():
var body = interact_ray.get_collider()
if interact_ray.get_collider().has_method("interact"):
body.interact()
held_key_check = 0.0
elif Input.is_action_just_released("interact"):
if held_item != null:
release_moveable()
elif interact_ray.is_colliding():
@@ -468,13 +476,6 @@ func _physics_process(delta):
if interact_ray.get_collider().get_class() == "RigidBody3D":
grab_moveable(body)
held_key_check = 0.0
elif Input.is_action_just_released("interact"):
if interact_ray.is_colliding():
var body = interact_ray.get_collider()
if interact_ray.get_collider().has_method("interact"):
body.interact()
held_key_check = 0.0
#kick
if Input.is_action_just_pressed("kick"):
if !animation_player.is_playing():
@@ -626,9 +627,8 @@ func hold_item(_delta):
if held_item != null:
interact_ray.look_at(held_item.global_position, Vector3.UP)
var held_dir = (moveable_holder.global_position - held_item.global_position) #+ hold_offset
held_item.linear_velocity = held_dir * 15
held_item.look_at(moveable_rotation.global_position, Vector3.UP)
held_item.linear_velocity = held_dir * 50
held_item.rotation = Vector3(0,held_item_rotation,0) + Vector3(0,camera.global_rotation.y,0)
#break when moved too far away
var distance_from_player = abs(self.global_position - held_item.global_position)
if distance_from_player.length() > 5:
@@ -647,7 +647,6 @@ func release_moveable():
held_item.set_collision_layer_value(1,held_item_collision_cache)
held_item = null
hold_offset = null
moveable_holder.rotation = Vector3(0,0,0)
## GUNS AND AMMO
func holster_gun(holster):

View File

@@ -43,7 +43,7 @@ func breaking(bullet_velocity):
#pickup drop
while number_of_drops > 0:
var pickup_spawn = level_control.item_pickup.instantiate()
var pickup_spawn = level_control.ITEM_PICKUP.instantiate()
var item_stats = level_control.pickup_spawn(false)
##SET VARIABLES

View File

@@ -204,7 +204,7 @@ func drop_loot(number_of_drops):
#pickup drop
while number_of_drops > 0:
var pickup_spawn = level_control.item_pickup.instantiate()
var pickup_spawn = level_control.ITEM_PICKUP.instantiate()
var item_stats = level_control.pickup_spawn(false)
##SET VARIABLES

View File

@@ -39,24 +39,23 @@ func interact():
func vend():
var item_vend
if is_pickup:
item_vend = level_control.item_pickup.instantiate()
item_vend = level_control.ITEM_PICKUP.instantiate()
var item_stats
item_stats = level_control.pickup_spawn(is_random)
##SET VARIABLES
item_vend.pickup_type = pickup_type
if level_control.player.gun != null:
if level_control.player.gun.ammo_type != 5:
item_vend.ammo_type = level_control.player.gun.ammo_type
if level_control.player.gun.weapon_info.bullet.ammo_type != 5:
item_vend.ammo_type = level_control.player.gun.weapon_info.bullet.ammo_type
else:
item_vend.ammo_type = item_stats["ammo_type"]
if pickup_type == 0:
if level_control.player.gun != null:
item_vend.value = level_control.player.gun.max_ammo
item_vend.value = level_control.player.gun.weapon_info.max_ammo
else:
item_vend.value = item_stats["value"]
else:
item_vend.value = pickup_amount
print("ITEM : ",item_vend.pickup_type,item_vend.ammo_type,item_vend.value)
else:
item_vend = item.instantiate()
item_vend.position = vend_ray.global_position

View File

@@ -8,6 +8,7 @@ class_name weapon_resource
@export_enum("Mag","Revolver","Bolt Action") var reload_type = 0
@export var bullet : bullet_resource
@export_enum("Auto", "Single", "Burst") var fire_mode: int
@export var hitscan_range : float = 100 ##for hitscan and melee weapons
@export var fov_zoom_amt = .98
@export var ads : bool = false
@export var recoil_amount : Vector3 = Vector3(.05,.05,.05)

View File

@@ -160,7 +160,6 @@ func spawn_casing():
instance_casing.player_velocity = player.velocity * transform.basis
get_tree().get_root().add_child(instance_casing)
func spawn_revolver_casings():
if casing_array.size() > 0:
var ammo_needed = weapon_info.max_ammo - GameGlobals.gun_ammo[weapon_info.gun_name]
@@ -271,6 +270,10 @@ func bullet_fire():
if weapon_info.fire_mode != 0:
cycle_count -= 1
func hitscan_fire():
# Fire hitscan
pass
func swapped_out():
queue_free()