tweaked item holder and added crouch

This commit is contained in:
derek
2024-12-05 16:55:29 -06:00
parent f6812b167f
commit 5d9bac5292
17 changed files with 133 additions and 89 deletions

View File

@@ -31,7 +31,7 @@ func _physics_process(delta):
distance_from_player = abs(self.global_position - player_position)
if distance_from_player.length() > 1.5:
if distance_from_player.length() > 2:
visible = true
if ray.is_colliding():

View File

@@ -6,6 +6,7 @@ const FLASHLIGHT_BRIGHTNESS = 30
const KICK_AMOUNT = 20
const LAND_CAMERA_TILT : Vector3 = Vector3(-1,0,0)
const WALK_SPEED = 12.0
const CROUCH_SPEED = 6.0
const SPRINT_SPEED = 15.0
const DASH_SPEED = 40
const SLOWSPEED = .1
@@ -74,8 +75,12 @@ var held_item_linear_damp_cache
var held_item_angular_damp_cache
var held_item_gravity_cache
var held_item_mass_cache
var held_item_collision_cache
var held_item_rotation = Vector3(0,0,0)
var gamespeed_controlled = false
var crouched_pos = Vector3(0,0,0)
var stand_pos = Vector3(0,0.889,0)
var crouched = false
# Slow Down Variables
var remaining_stamina : float = MAX_STAMINA
@@ -108,7 +113,8 @@ var controlled_elsewhere = false
@onready var kick_audio: AudioStreamPlayer3D = $Head/Recoil/Camera3D/Audio/Kick
@onready var weapon_pickup_audio: AudioStreamPlayer = $Audio/WeaponPickup
@onready var crt_filter: ColorRect = $Head/Recoil/Camera3D/crtFilter
@onready var moveable_holder: Node3D = $Head/MoveableHolder
@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
@@ -131,6 +137,8 @@ func _ready():
health_indicator.size = Vector2(viewportWidth,viewportHeight)
health_indicator.color = Color(0.471, 0, 0, 0)
speed = WALK_SPEED
crt_filter.visible = false
#turn off audio if unchecked in player
@@ -173,10 +181,10 @@ func _physics_process(delta):
velocity.y += JUMP_VELOCITY
double_jump = false
speed = WALK_SPEED #the fuck is this line doing
if Input.is_action_just_pressed("crouch"):
velocity.y -= JUMP_VELOCITY * 4
crouched = !crouched
# Get the input direction and handle the movement/deceleration.
var input_dir = Input.get_vector("move_left", "move_right", "move_up", "move_down")
@@ -308,7 +316,7 @@ func _physics_process(delta):
gun.anim_player.play("swap_out")
level_control.gun_spawn(level_control.current_gun_index + 1)
else:
held_item_rotation.y = clamp(held_item_rotation.y + deg_to_rad(45), deg_to_rad(0),deg_to_rad(360))
moveable_holder.rotation.y += deg_to_rad(45)
#Weapon Swap Down
if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing():
@@ -317,7 +325,7 @@ func _physics_process(delta):
gun.anim_player.play("swap_out")
level_control.gun_spawn(level_control.current_gun_index - 1)
else:
held_item_rotation.y = clamp(held_item_rotation.y - deg_to_rad(45), deg_to_rad(0),deg_to_rad(360))
moveable_holder.rotation.y -= deg_to_rad(45)
for i in range(10):
if Input.is_action_just_pressed("numb_" + str(i)):
@@ -354,12 +362,22 @@ func _physics_process(delta):
if level_control.health <= 0:
level_control.die()
hold_item()
hold_item(delta)
move_and_slide()
crouch(delta)
weapon_tilt(input_dir.x, delta)
weapon_sway(delta)
weapon_bob(velocity.length(), delta)
func crouch(delta):
if crouched:
if head.position != crouched_pos:
head.position = lerp(head.position, crouched_pos, delta * 8)
speed = CROUCH_SPEED
else:
if head.position != stand_pos:
head.position = lerp(head.position, stand_pos, delta * 8)
speed = WALK_SPEED
func _headbob(time) -> Vector3:
var pos = Vector3.ZERO
@@ -379,7 +397,7 @@ func _on_pick_up_detection_body_entered(body):
weapon_pickup_audio.play()
func ladder_collide(is_climbing):
func ladder_collide():
if is_climbing == true:
gravity = 0.0
else:
@@ -442,28 +460,28 @@ func toggle_hud(hud_on):
stamina_counter.visible = hud_on
func grab_moveable(body):
moveable_holder.global_position = body.global_position
held_item = body
held_item_rotation = Vector3(0,0,0)#body.rotation
#cache rigidbody settings
held_item_linear_damp_cache = body.linear_damp
held_item_angular_damp_cache = body.angular_damp
held_item_gravity_cache = body.gravity_scale
held_item_mass_cache = body.mass
held_item_collision_cache = held_item.get_collision_layer_value(1)
#change rigidbody settings
body.linear_damp = 0 #5
body.angular_damp = 0 #5
body.mass = 1
held_item.gravity_scale = 0
held_item.set_collision_layer_value(1,false)
func hold_item():
func hold_item(_delta):
# Move Held Items
if held_item != null:
var held_dir = moveable_holder.global_position - held_item.global_position
var held_av = held_item_rotation - held_item.rotation
interact_ray.look_at(held_item.global_position, Vector3.UP)
var hold_offset = held_item.global_position - interact_ray.get_collision_point()
var held_dir = (moveable_holder.global_position - held_item.global_position) + hold_offset
held_item.linear_velocity = held_dir * 15
held_item.look_at(camera.global_position)
#held_item.angular_velocity = held_av * 10
held_item.look_at(moveable_rotation.global_position, Vector3.UP)
#break when moved too far away
var distance_from_player = abs(self.global_position - held_item.global_position)
@@ -474,12 +492,14 @@ func hold_item():
release_moveable()
func release_moveable():
held_item_rotation = Vector3(0,0,0)
held_item.gravity_scale = held_item_gravity_cache
held_item.linear_damp = held_item_linear_damp_cache
held_item.angular_damp = held_item_angular_damp_cache
held_item.mass = held_item_mass_cache
held_item = null
if held_item != null:
held_item.gravity_scale = held_item_gravity_cache
held_item.linear_damp = held_item_linear_damp_cache
held_item.angular_damp = held_item_angular_damp_cache
held_item.mass = held_item_mass_cache
held_item.set_collision_layer_value(1,held_item_collision_cache)
held_item = null
moveable_holder.rotation = Vector3(0,0,0)
func hit(damage, fired_by, target_type):
level_control.health -= damage