weapon select tweaks added joy support

This commit is contained in:
Derek
2024-12-14 17:23:54 -06:00
parent ec75bffb70
commit a06ae6f74d
9 changed files with 6582 additions and 25 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://r81nhtx6mf5t"
path="res://.godot/imported/Cursor 1@0.5x.png-270a2d0b10532a3d12e94be67559efa3.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/UI/Edit Files/0.5x/Cursor 1@0.5x.png"
dest_files=["res://.godot/imported/Cursor 1@0.5x.png-270a2d0b10532a3d12e94be67559efa3.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

File diff suppressed because it is too large Load Diff

View File

@@ -129,7 +129,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0341401, -0.111267)
transform = Transform3D(1, -2.5409e-11, -1.16415e-10, 3.69482e-12, 1, 0, 1.16415e-10, 2.32831e-10, 1, 0.269894, -0.199195, -0.580209)
[node name="Flashlight" type="SpotLight3D" parent="Head/Recoil/Camera3D/WeaponHolder"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.183578, -0.664453)
transform = Transform3D(1, -1.08571e-11, -5.82077e-11, 3.75167e-12, 1, 0, 5.82077e-11, 1.16415e-10, 1, -0.000444638, -0.184371, 0.0974539)
light_color = Color(1, 1, 0.898039, 1)
light_energy = 0.0
light_projector = ExtResource("4_x670l")

View File

@@ -0,0 +1,44 @@
[gd_scene load_steps=7 format=3 uid="uid://domhm87hbhbg1"]
[ext_resource type="Script" path="res://demo/src/Player.gd" id="1_nm1yx"]
[ext_resource type="Script" path="res://demo/src/CameraManager.gd" id="2_loos7"]
[sub_resource type="SphereShape3D" id="SphereShape3D_smq6u"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_lwhhq"]
height = 1.5
[sub_resource type="SeparationRayShape3D" id="SeparationRayShape3D_twc2s"]
[sub_resource type="CapsuleMesh" id="CapsuleMesh_lsqiy"]
[node name="Player" type="CharacterBody3D"]
collision_layer = 2
script = ExtResource("1_nm1yx")
[node name="CameraManager" type="Node3D" parent="."]
script = ExtResource("2_loos7")
[node name="Arm" type="SpringArm3D" parent="CameraManager"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 0.906308, 0.422618, 0, -0.422618, 0.906308, 0, 2.32515, -0.0321627)
shape = SubResource("SphereShape3D_smq6u")
spring_length = 6.0
margin = 0.5
[node name="Camera3D" type="Camera3D" parent="CameraManager/Arm"]
unique_name_in_owner = true
near = 0.25
far = 16384.0
[node name="CollisionShapeBody" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.25, 0)
shape = SubResource("CapsuleShape3D_lwhhq")
[node name="CollisionShapeRay" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 1, 0)
shape = SubResource("SeparationRayShape3D_twc2s")
[node name="Body" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
mesh = SubResource("CapsuleMesh_lsqiy")

81
demo/src/Player.gd Normal file
View File

@@ -0,0 +1,81 @@
extends CharacterBody3D
@export var MOVE_SPEED: float = 50.0
@export var JUMP_SPEED: float = 2.0
@export var first_person: bool = false :
set(p_value):
first_person = p_value
if first_person:
var tween: Tween = create_tween()
tween.tween_property($CameraManager/Arm, "spring_length", 0.0, .33)
tween.tween_callback($Body.set_visible.bind(false))
else:
$Body.visible = true
create_tween().tween_property($CameraManager/Arm, "spring_length", 6.0, .33)
@export var gravity_enabled: bool = true :
set(p_value):
gravity_enabled = p_value
if not gravity_enabled:
velocity.y = 0
@export var collision_enabled: bool = true :
set(p_value):
collision_enabled = p_value
$CollisionShapeBody.disabled = ! collision_enabled
$CollisionShapeRay.disabled = ! collision_enabled
func _physics_process(p_delta) -> void:
var direction: Vector3 = get_camera_relative_input()
var h_veloc: Vector2 = Vector2(direction.x, direction.z) * MOVE_SPEED
if Input.is_key_pressed(KEY_SHIFT):
h_veloc *= 2
velocity.x = h_veloc.x
velocity.z = h_veloc.y
if gravity_enabled:
velocity.y -= 40 * p_delta
move_and_slide()
# Returns the input vector relative to the camera. Forward is always the direction the camera is facing
func get_camera_relative_input() -> Vector3:
var input_dir: Vector3 = Vector3.ZERO
if Input.is_key_pressed(KEY_A): # Left
input_dir -= %Camera3D.global_transform.basis.x
if Input.is_key_pressed(KEY_D): # Right
input_dir += %Camera3D.global_transform.basis.x
if Input.is_key_pressed(KEY_W): # Forward
input_dir -= %Camera3D.global_transform.basis.z
if Input.is_key_pressed(KEY_S): # Backward
input_dir += %Camera3D.global_transform.basis.z
if Input.is_key_pressed(KEY_E) or Input.is_key_pressed(KEY_SPACE): # Up
velocity.y += JUMP_SPEED + MOVE_SPEED*.016
if Input.is_key_pressed(KEY_Q): # Down
velocity.y -= JUMP_SPEED + MOVE_SPEED*.016
if Input.is_key_pressed(KEY_KP_ADD) or Input.is_key_pressed(KEY_EQUAL):
MOVE_SPEED = clamp(MOVE_SPEED + .5, 5, 9999)
if Input.is_key_pressed(KEY_KP_SUBTRACT) or Input.is_key_pressed(KEY_MINUS):
MOVE_SPEED = clamp(MOVE_SPEED - .5, 5, 9999)
return input_dir
func _input(p_event: InputEvent) -> void:
if p_event is InputEventMouseButton and p_event.pressed:
if p_event.button_index == MOUSE_BUTTON_WHEEL_UP:
MOVE_SPEED = clamp(MOVE_SPEED + 5, 5, 9999)
elif p_event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
MOVE_SPEED = clamp(MOVE_SPEED - 5, 5, 9999)
elif p_event is InputEventKey:
if p_event.pressed:
if p_event.keycode == KEY_V:
first_person = ! first_person
elif p_event.keycode == KEY_G:
gravity_enabled = ! gravity_enabled
elif p_event.keycode == KEY_C:
collision_enabled = ! collision_enabled
# Else if up/down released
elif p_event.keycode in [ KEY_Q, KEY_E, KEY_SPACE ]:
velocity.y = 0

View File

@@ -11,7 +11,7 @@ config_version=5
[application]
config/name="First Person Test"
run/main_scene="res://scenes/asset_checker.tscn"
run/main_scene="res://assets/blockout_2.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
config/icon="res://icon.svg"
@@ -27,6 +27,7 @@ HelperFuncs="*res://scripts/HelperFuncs.gd"
[display]
window/size/mode=3
mouse_cursor/custom_image="res://assets/UI/Edit Files/0.5x/Cursor 1@0.5x.png"
[editor]

View File

@@ -23,7 +23,7 @@ const ADS_POS = Vector3(0,-.05,-.45)
#JOYSTICK SETTINGS
const JOYSTICK_SENSITIVITY = .06
var adj_sensitivity = JOYSTICK_SENSITIVITY
const R_JOYSTICK_DEADZONE = 0.05
const R_JOYSTICK_DEADZONE = 0.1
const L_JOYSTICK_DEADZONE = .2
const L_JOYSTICK_SENSITIVITY = .1
@@ -392,7 +392,6 @@ func _physics_process(delta):
if Input.is_action_just_pressed("weapon_select"):
weapon_select_menu.open()
Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN)
controlled_elsewhere = true
gamespeed_controlled = true
Engine.time_scale = .01
@@ -401,8 +400,9 @@ func _physics_process(delta):
if selection != null and selection != level_control.current_gun_index :
weapon_select(selection)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
controlled_elsewhere = false
gamespeed_controlled = false
await get_tree().create_timer(.2).timeout
controlled_elsewhere = false
#interact button
if Input.is_action_just_pressed("interact"):
@@ -459,16 +459,17 @@ func joypad_walk():
return dir_out
func joypad_look(delta):
# Joypad right stick look control
var xAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)
var yAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)
var aim_assist
if !controlled_elsewhere:
# Joypad right stick look control
var xAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)
var yAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)
var aim_assist
if abs(xAxis) > R_JOYSTICK_DEADZONE:
self.rotate_y(-xAxis * JOYSTICK_SENSITIVITY * 1)
if abs(yAxis) > R_JOYSTICK_DEADZONE:
head.rotate_x(-yAxis * JOYSTICK_SENSITIVITY * 1)
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(85))
if abs(xAxis) > R_JOYSTICK_DEADZONE:
self.rotate_y(-xAxis * JOYSTICK_SENSITIVITY * 1)
if abs(yAxis) > R_JOYSTICK_DEADZONE:
head.rotate_x(-yAxis * JOYSTICK_SENSITIVITY * 1)
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-90), deg_to_rad(85))
func flashlight_toggle():
if flashlight_on:

View File

@@ -3,7 +3,10 @@ extends Control
@export var line_width : int = 4
@onready var player: CharacterBody3D = $"../../../.."
@onready var level_control = get_tree().current_scene
var selecting
var options = []
const outer_radius : int = 500
@@ -17,10 +20,13 @@ const IMAGE_SIZE = Vector2(512,512)
var selection
func open():
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
selecting = true
show()
update_weapon_list()
func close():
selecting = false
hide()
return selection
@@ -29,20 +35,33 @@ func _ready() -> void:
update_weapon_list()
SignalBus.weapon_list_changed.connect(update_weapon_list)
func _input(event: InputEvent) -> void:
if selecting:
const MOUSE_DEADZONE = .01
if event is InputEventMouseMotion:
if abs(event.relative.x) > MOUSE_DEADZONE or abs(event.relative.x) > MOUSE_DEADZONE:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var mouse_pos = get_local_mouse_position()
var mouse_radius = mouse_pos.length()
if mouse_radius < inner_radius:
selection = null
else:
var mouse_rads = fposmod(mouse_pos.angle() * -1, TAU)
selection = ceil((mouse_rads / TAU) * (len(options)+1))
queue_redraw()
if selecting:
var mouse_pos = get_local_mouse_position()
var mouse_radius = mouse_pos.length()
if mouse_radius < inner_radius:
selection = null
else:
var mouse_rads = fposmod(mouse_pos.angle() * -1, TAU)
selection = ceil((mouse_rads / TAU) * (len(options)))
var joy_input = joypad_select()
if abs(joy_input) > Vector2.ZERO:
var joy_rads = fposmod(joypad_select().angle() * -1, TAU)
selection = ceil((joy_rads / TAU) * (len(options)))
queue_redraw()
func _draw():
var offset = IMAGE_SIZE/ -2
@@ -102,3 +121,15 @@ func _draw():
func update_weapon_list():
options = level_control.held_guns
func joypad_select():
var joy_out = Vector2.ZERO
# Joypad right stick look control
var xAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_X)
var yAxis = Input.get_joy_axis(0,JOY_AXIS_RIGHT_Y)
if abs(xAxis) > player.R_JOYSTICK_DEADZONE:
joy_out.x = xAxis
if abs(yAxis) > player.R_JOYSTICK_DEADZONE:
joy_out.y = yAxis
return joy_out