Add shot and reload actions

This commit is contained in:
Nikolai Rodionov 2025-01-16 17:42:44 +01:00
parent 7b0de72911
commit 7ec7cf189c
Signed by: allanger
GPG Key ID: 09F8B434D0FDD99B
8 changed files with 86 additions and 7 deletions

Binary file not shown.

View File

@ -0,0 +1,19 @@
[remap]
importer="mp3"
type="AudioStreamMP3"
uid="uid://dnr6vk5fx450x"
path="res://.godot/imported/gun-shot-demo.mp3-c035d09f101c7f5d3f4a4028455c8980.mp3str"
[deps]
source_file="res://assets/sounds/gun-shot-demo.mp3"
dest_files=["res://.godot/imported/gun-shot-demo.mp3-c035d09f101c7f5d3f4a4028455c8980.mp3str"]
[params]
loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

View File

@ -17,7 +17,10 @@ config/icon="res://icon.svg"
[display]
window/size/mode=3
window/size/viewport_width=1920
window/size/viewport_height=1080
window/size/mode=4
window/size/borderless=true
[input]
@ -51,3 +54,13 @@ exit={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
shot={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
reload={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
]
}

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://ccm77j5rkh21w"]
[gd_scene load_steps=6 format=3 uid="uid://ccm77j5rkh21w"]
[ext_resource type="Script" path="res://scripts/character_controller.gd" id="1_sue4n"]
[ext_resource type="PackedScene" uid="uid://d21giy40pnjhe" path="res://scenes/weapon/pistol.tscn" id="2_blr4e"]
[ext_resource type="Texture2D" uid="uid://d1nfjip21kjpu" path="res://addons/kenney_prototype_textures/orange/texture_13.png" id="2_i60ip"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_m6bjf"]
@ -17,12 +18,18 @@ script = ExtResource("1_sue4n")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.975222, 0)
material_override = SubResource("StandardMaterial3D_m6bjf")
[node name="CameraMount" type="Node3D" parent="CharacterBody3D/Body"]
transform = Transform3D(1, 0, 0, 0, 0.999971, 0.00759248, 0, -0.00759248, 0.999971, 0, 0.951, 0)
[node name="UpperTorso" type="CSGSphere3D" parent="CharacterBody3D/Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.298181, 0)
[node name="Camera" type="Camera3D" parent="CharacterBody3D/Body/CameraMount"]
[node name="CameraMount" type="Node3D" parent="CharacterBody3D/Body/UpperTorso"]
transform = Transform3D(1, 0, 0, 0, 0.999971, 0.00759248, 0, -0.00759248, 0.999971, 0, 0.212444, 0)
[node name="Camera" type="Camera3D" parent="CharacterBody3D/Body/UpperTorso/CameraMount"]
transform = Transform3D(1, 0, 0, 0, 1, -4.65661e-10, 0, 0, 1, 0, 0.0051769, -0.68182)
[node name="Pistol" parent="CharacterBody3D/Body/UpperTorso" instance=ExtResource("2_blr4e")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.26718, -0.000199199, -0.945376)
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.981342, 0)
shape = SubResource("CylinderShape3D_1sre5")

View File

@ -0,0 +1,5 @@
[gd_scene load_steps=2 format=3 uid="uid://b50vg1umdgjas"]
[ext_resource type="PackedScene" uid="uid://dumj5qqh2h2tg" path="res://assets/models/weapon/DEAGLE/DEAGLE.glb" id="1_5xic7"]
[node name="DEAGLE" instance=ExtResource("1_5xic7")]

21
scenes/weapon/pistol.gd Normal file
View File

@ -0,0 +1,21 @@
extends Node3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# TODO: Handle the shot logic
func shot():
var pistol := $DEAGLE
pistol.rotate_z(20.0)
# TODO: Handle the reload logic
func reload():
var pistol := $DEAGLE
pistol.rotate_z(-20.0)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=3 uid="uid://d21giy40pnjhe"]
[ext_resource type="PackedScene" uid="uid://dumj5qqh2h2tg" path="res://assets/models/weapon/DEAGLE/DEAGLE.glb" id="1_ard7n"]
[ext_resource type="Script" path="res://scenes/weapon/pistol.gd" id="1_jgbvq"]
[node name="Pistol" type="Node3D"]
script = ExtResource("1_jgbvq")
[node name="DEAGLE" parent="." instance=ExtResource("1_ard7n")]

View File

@ -22,7 +22,8 @@ var walk_vel: Vector3 # Walking velocity
var grav_vel: Vector3 # Gravity velocity
var jump_vel: Vector3 # Jumping velocity
@onready var camera: Node3D = $Body/CameraMount
@onready var camera: Node3D = $Body/UpperTorso
@onready var character: Node3D = $"."
func _ready() -> void:
capture_mouse()
@ -33,10 +34,14 @@ func _unhandled_input(event: InputEvent) -> void:
if mouse_captured: _rotate_camera()
if Input.is_action_just_pressed("jump"): jumping = true
if Input.is_action_just_pressed("exit"): get_tree().quit()
if Input.is_action_just_pressed("shot"): $Body/UpperTorso/Pistol.shot()
if Input.is_action_just_pressed("reload"): $Body/UpperTorso/Pistol.reload()
func _physics_process(delta: float) -> void:
if mouse_captured: _handle_joypad_camera_rotation(delta)
velocity = _walk(delta) + _gravity(delta) + _jump(delta)
move_and_slide()
func capture_mouse() -> void:
@ -48,7 +53,7 @@ func release_mouse() -> void:
mouse_captured = false
func _rotate_camera(sens_mod: float = 1.0) -> void:
camera.rotation.y -= look_dir.x * camera_sens * sens_mod
character.rotation.y -= look_dir.x * camera_sens * sens_mod
camera.rotation.x = clamp(camera.rotation.x - look_dir.y * camera_sens * sens_mod, -1.5, 1.5)
func _handle_joypad_camera_rotation(delta: float, sens_mod: float = 1.0) -> void: