started fixing hud to prevent crosshair from wobbling
This commit is contained in:
@@ -3,6 +3,7 @@ class_name Chest
|
||||
|
||||
@export var weapon_drops : Array[Resource]
|
||||
@export var health : float = 30
|
||||
@export var outline_meshes : Array[MeshInstance3D]
|
||||
@onready var serial_label: Label3D = $chest_lid/serial_number
|
||||
|
||||
var serial_number
|
||||
@@ -29,9 +30,15 @@ func _process(delta: float) -> void:
|
||||
func hit(dam):
|
||||
health -= dam
|
||||
if !open and health <= 0:
|
||||
anim_player.play("open")
|
||||
open = true
|
||||
|
||||
open_chest()
|
||||
|
||||
func open_chest():
|
||||
anim_player.play("open")
|
||||
if outline_meshes != null:
|
||||
for i in outline_meshes:
|
||||
i.visible = false
|
||||
open = true
|
||||
|
||||
func spawn_drop():
|
||||
drop_weapon.position = item_spawn.global_position
|
||||
drop_weapon.transform.basis = item_spawn.global_transform.basis
|
||||
|
||||
@@ -16,18 +16,19 @@ var crosshair_target
|
||||
|
||||
@onready var level_control = get_tree().current_scene
|
||||
@onready var player = level_control.player
|
||||
@onready var stamina_bar: TextureProgressBar = $StaminaBar
|
||||
@onready var stamina_bar_2: ProgressBar = $StaminaBar2
|
||||
@onready var health_bar: ProgressBar = $HealthBar
|
||||
@onready var ammo_counter: HBoxContainer = $GunInfo/VBoxContainer/AmmoCounter
|
||||
@onready var gun_name: Label = $"GunInfo/VBoxContainer/Gun Name"
|
||||
@onready var ammo_current: Label = $GunInfo/VBoxContainer/AmmoCounter/AmmoCurrent
|
||||
@onready var ammo_reserve: Label = $GunInfo/VBoxContainer/AmmoCounter/AmmoReserve
|
||||
@onready var gun_info: MarginContainer = $GunInfo
|
||||
@onready var money: Label = $Money
|
||||
@onready var crosshair: TextureRect = $Crosshair
|
||||
@onready var crosshair_center: TextureRect = $CrosshairCenter
|
||||
@onready var stamina_bar: TextureProgressBar = $StaticItems/StaminaBar
|
||||
@onready var stamina_bar_2: ProgressBar = $StaticItems/StaminaBar2
|
||||
@onready var health_bar: ProgressBar = $WobbleItems/HealthBar
|
||||
@onready var ammo_counter: HBoxContainer = $WobbleItems/GunInfo/VBoxContainer/AmmoCounter
|
||||
@onready var gun_name: Label = $"WobbleItems/GunInfo/VBoxContainer/Gun Name"
|
||||
@onready var ammo_current: Label = $WobbleItems/GunInfo/VBoxContainer/AmmoCounter/AmmoCurrent
|
||||
@onready var ammo_reserve: Label = $WobbleItems/GunInfo/VBoxContainer/AmmoCounter/AmmoReserve
|
||||
@onready var gun_info: MarginContainer = $WobbleItems/GunInfo
|
||||
@onready var money: Label = $WobbleItems/Money
|
||||
@onready var crosshair: TextureRect = $StaticItems/Crosshair
|
||||
@onready var crosshair_center: TextureRect = $StaticItems/CrosshairCenter
|
||||
@onready var pickup_item_indicator = preload("res://assets/pickup_item_indicator.tscn")
|
||||
@onready var wobble_items: Control = $WobbleItems
|
||||
|
||||
const FULL_WHITE = Color(1, 1, 1, 1)
|
||||
const TRANSPARENT = Color(1, 1, 1, 0)
|
||||
@@ -173,6 +174,8 @@ func _process(delta: float) -> void:
|
||||
|
||||
## SPAWN NOTIFICATIONS
|
||||
spawn_notifs()
|
||||
|
||||
wobble_items.position = hud_wobble(delta)
|
||||
|
||||
func crosshair_size_change():
|
||||
crosshair_target += Vector2(20,20)
|
||||
@@ -220,3 +223,20 @@ func spawn_notifs():
|
||||
|
||||
func player_hit():
|
||||
crosshair_size_change()
|
||||
|
||||
func hud_wobble(delta):
|
||||
var viewport_height_adj = (get_viewport().size.y/1080)
|
||||
|
||||
var HUD_WOBBLE_MAX : float = 40 * viewport_height_adj
|
||||
var MOUSE_AMT = 10 * viewport_height_adj
|
||||
var VELOCITY_AMT = 100 * viewport_height_adj
|
||||
var HUD_SPEED = 10 * viewport_height_adj
|
||||
|
||||
var dir_mouse = Vector2(-player.mouse_input.x * MOUSE_AMT,-player.mouse_input.y * MOUSE_AMT)
|
||||
var velocity_dir_transformed = player.velocity.normalized() * player.global_basis
|
||||
var velocity_lengh_clamped = clamp(player.velocity.length(),-VELOCITY_AMT,VELOCITY_AMT)
|
||||
var dir_velocity = Vector2(-velocity_dir_transformed.x * velocity_lengh_clamped,velocity_dir_transformed.y * velocity_lengh_clamped)
|
||||
var dir_clamped = clamp(dir_mouse + dir_velocity,Vector2(-HUD_WOBBLE_MAX,-HUD_WOBBLE_MAX),Vector2(HUD_WOBBLE_MAX,HUD_WOBBLE_MAX))
|
||||
var offset = lerp(position, dir_clamped, delta * HUD_SPEED)
|
||||
|
||||
return offset
|
||||
|
||||
@@ -476,7 +476,6 @@ func _physics_process(delta):
|
||||
joypad_look()
|
||||
aim_down_sights(delta)
|
||||
flashlight_toggle()
|
||||
hud_wobble(delta)
|
||||
hold_item(delta)
|
||||
move_and_slide()
|
||||
crouch(delta)
|
||||
@@ -591,23 +590,6 @@ func aim_down_sights(delta):
|
||||
else:
|
||||
gun.position = lerp(gun.position, weapon_start_pos,(delta * 100)/Engine.time_scale)
|
||||
|
||||
func hud_wobble(delta):
|
||||
var viewport_height_adj = (get_viewport().size.y/1080)
|
||||
|
||||
var HUD_WOBBLE_MAX : float = 40 * viewport_height_adj
|
||||
var MOUSE_AMT = 10 * viewport_height_adj
|
||||
var VELOCITY_AMT = 100 * viewport_height_adj
|
||||
var HUD_SPEED = 10 * viewport_height_adj
|
||||
|
||||
var dir_mouse = Vector2(-mouse_input.x * MOUSE_AMT,-mouse_input.y * MOUSE_AMT)
|
||||
var velocity_dir_transformed = velocity.normalized() * global_basis
|
||||
var velocity_lengh_clamped = clamp(velocity.length(),-VELOCITY_AMT,VELOCITY_AMT)
|
||||
var dir_velocity = Vector2(-velocity_dir_transformed.x * velocity_lengh_clamped,velocity_dir_transformed.y * velocity_lengh_clamped)
|
||||
var dir_clamped = clamp(dir_mouse + dir_velocity,Vector2(-HUD_WOBBLE_MAX,-HUD_WOBBLE_MAX),Vector2(HUD_WOBBLE_MAX,HUD_WOBBLE_MAX))
|
||||
var offset = lerp(hud.position, dir_clamped, delta * HUD_SPEED)
|
||||
hud.position = offset
|
||||
hud.crosshair.position = -offset
|
||||
|
||||
func grab_moveable(body):
|
||||
held_item_cache = {
|
||||
"gravity_scale" : body.gravity_scale
|
||||
|
||||
@@ -10,3 +10,12 @@ var bullet_force_mod
|
||||
var bullet_speed
|
||||
var blast_power
|
||||
var blast_radius
|
||||
|
||||
func _ready() -> void:
|
||||
visible = false
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var distance_from_player = abs(self.global_position - player_position)
|
||||
|
||||
if distance_from_player.length() > 2:
|
||||
visible = true
|
||||
|
||||
@@ -5,11 +5,6 @@ extends RigidBody3D
|
||||
func _ready() -> void:
|
||||
add_to_group("persist")
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func save():
|
||||
var save_dict = {
|
||||
"filename" : get_scene_file_path(),
|
||||
|
||||
Reference in New Issue
Block a user