First shooting implementation #3

Merged
allanger merged 1 commits from shoot into main 2025-01-22 05:12:23 +00:00
13 changed files with 259 additions and 76 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,9 +1,8 @@
[gd_scene load_steps=14 format=3 uid="uid://hivk5ek6u887"]
[ext_resource type="Texture2D" uid="uid://du0f7hc4skged" path="res://addons/kenney_prototype_textures/dark/texture_06.png" id="1_lae2b"]
[ext_resource type="Texture2D" uid="uid://dmge3tk7w0b1n" path="res://addons/kenney_prototype_textures/dark/texture_01.png" id="2_7newm"]
[ext_resource type="PackedScene" uid="uid://cn7ty4xcbiqaf" path="res://assets/models/character/character.glb" id="3_exa4b"]
[ext_resource type="PackedScene" uid="uid://ccm77j5rkh21w" path="res://scenes/utils/character.tscn" id="3_omcjn"]
[ext_resource type="Texture2D" uid="uid://c5uytbu1wc1bq" path="res://addons/kenney_prototype_textures/orange/texture_09.png" id="1_llm1c"]
[ext_resource type="Texture2D" uid="uid://e4nd8b6f0tw7" path="res://addons/kenney_prototype_textures/dark/texture_04.png" id="2_k2arh"]
[ext_resource type="PackedScene" uid="uid://1j5ajc26w5xk" path="res://scenes/utils/character_bak.tscn" id="3_6anfg"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_bcdcw"]
albedo_texture = ExtResource("1_lae2b")
@ -40,77 +39,38 @@ volumetric_fog_density = 0.0
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 50, 0)
shadow_enabled = true
[node name="Base" type="Node3D" parent="."]
[node name="World" type="Node3D" parent="."]
[node name="Floor" type="CSGBox3D" parent="Base"]
material_override = SubResource("StandardMaterial3D_bcdcw")
[node name="Base" type="Node3D" parent="World"]
[node name="Floor" type="CSGBox3D" parent="World/Base"]
use_collision = true
size = Vector3(100, 1, 100)
[node name="Wall_1" type="CSGBox3D" parent="Base"]
[node name="Wall_1" type="CSGBox3D" parent="World/Base"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 50, 0, 0)
material_override = SubResource("StandardMaterial3D_p4psn")
use_collision = true
size = Vector3(1, 20, 100)
[node name="Wall_2" type="CSGBox3D" parent="Base"]
[node name="Wall_2" type="CSGBox3D" parent="World/Base"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -50, 0, 0)
material_override = SubResource("StandardMaterial3D_0jiki")
use_collision = true
size = Vector3(1, 20, 100)
[node name="Wall_3" type="CSGBox3D" parent="Base"]
[node name="Wall_3" type="CSGBox3D" parent="World/Base"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 50)
material_override = SubResource("StandardMaterial3D_1pwnn")
use_collision = true
size = Vector3(100, 20, 1)
[node name="Wall_4" type="CSGBox3D" parent="Base"]
[node name="Wall_4" type="CSGBox3D" parent="World/Base"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -50)
material_override = SubResource("StandardMaterial3D_1yo6k")
use_collision = true
size = Vector3(100, 20, 1)
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_5t2t5")
camera_attributes = SubResource("CameraAttributesPractical_32hnm")
[node name="Room" type="Node3D" parent="."]
[node name="Roof" type="CSGBox3D" parent="Room"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 40, 10, 40)
use_collision = true
size = Vector3(20, 1, 20)
[node name="Box2" type="CSGBox3D" parent="Room"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 31.4113, -0.977205, 30.1989)
use_collision = true
size = Vector3(15, 4, 5)
[node name="Box2" type="CSGBox3D" parent="Room/Box2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.808781, 0.545475, -9.7784)
use_collision = true
size = Vector3(15, 4, 5)
[node name="Box" type="CSGBox3D" parent="Room"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 45.354, 2, 30)
use_collision = true
size = Vector3(15, 4, 5)
[node name="Box3" type="CSGBox3D" parent="Room"]
transform = Transform3D(0.919513, -0.393059, 0, 0.393059, 0.919513, 0, 0, 0, 1, -1.57507, -0.966964, 27.4611)
use_collision = true
size = Vector3(15, 4, 5)
[node name="Box4" type="CSGBox3D" parent="Room"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 14.9181, -1.39989, 28.83)
use_collision = true
size = Vector3(15, 4, 5)
[node name="character" parent="Room" instance=ExtResource("3_exa4b")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.2581, 0.499998, 16.9319)
[node name="Character" parent="." instance=ExtResource("3_omcjn")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
[node name="Character" parent="World" instance=ExtResource("3_6anfg")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 14.6432, 0)

View File

@ -1,8 +1,10 @@
[gd_scene load_steps=9 format=3 uid="uid://ccm77j5rkh21w"]
[gd_scene load_steps=11 format=3 uid="uid://ccm77j5rkh21w"]
[ext_resource type="Script" path="res://scripts/character_controller.gd" id="1_sue4n"]
[ext_resource type="PackedScene" uid="uid://ceywbkneyatpw" path="res://scenes/utils/body.tscn" id="2_2couv"]
[ext_resource type="PackedScene" uid="uid://bmqutwuj28san" path="res://scenes/utils/view_model_camera.tscn" id="4_al83x"]
[ext_resource type="Script" path="res://scenes/weapon/pistol.gd" id="4_uwcjh"]
[ext_resource type="PackedScene" uid="uid://d21giy40pnjhe" path="res://scenes/weapon/pistol.tscn" id="5_6k7rq"]
[ext_resource type="PackedScene" uid="uid://cn7ty4xcbiqaf" path="res://assets/models/character/character.glb" id="8_42pl8"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_adkee"]
@ -100,7 +102,7 @@ script = ExtResource("1_sue4n")
ANIMATION_PLAYER = NodePath("AnimationPlayer")
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 0.439226, 0, 0.9, 0)
transform = Transform3D(1, 0, 0, 0, 1.66022, 0, 0, 0, 0.967678, 0, 0.9, 0)
shape = SubResource("CapsuleShape3D_adkee")
[node name="character" parent="CharacterBody3D" instance=ExtResource("2_2couv")]
@ -113,6 +115,12 @@ radius = 0.001
[node name="ViewModelCamera" parent="CharacterBody3D/UpperTorso" instance=ExtResource("4_al83x")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00122696, 0.093623, -0.179357)
script = ExtResource("4_uwcjh")
[node name="Pistol" parent="CharacterBody3D/UpperTorso/ViewModelCamera" instance=ExtResource("5_6k7rq")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -0.0287516, -0.136104, -0.276055)
visible = false
script = null
[node name="AnimationPlayer" type="AnimationPlayer" parent="CharacterBody3D"]
root_node = NodePath("../CollisionShape3D")
@ -121,6 +129,7 @@ libraries = {
}
[node name="RealBody" type="Node3D" parent="CharacterBody3D"]
visible = false
[node name="character2" parent="CharacterBody3D/RealBody" instance=ExtResource("8_42pl8")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, -0.0147014)

View File

@ -0,0 +1,42 @@
[gd_scene load_steps=7 format=3 uid="uid://1j5ajc26w5xk"]
[ext_resource type="Script" path="res://scripts/character_controller.gd" id="1_vb71f"]
[ext_resource type="Texture2D" uid="uid://d1nfjip21kjpu" path="res://addons/kenney_prototype_textures/orange/texture_13.png" id="2_j4i2j"]
[ext_resource type="Script" path="res://scenes/weapon/pistol.gd" id="3_gblkg"]
[ext_resource type="PackedScene" uid="uid://d21giy40pnjhe" path="res://scenes/weapon/pistol.tscn" id="4_xw0oh"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_m6bjf"]
albedo_texture = ExtResource("2_j4i2j")
[sub_resource type="CylinderShape3D" id="CylinderShape3D_1sre5"]
radius = 0.227448
[node name="Character" type="Node3D"]
[node name="CharacterBody3D" type="CharacterBody3D" parent="."]
script = ExtResource("1_vb71f")
[node name="Body" type="CSGCylinder3D" parent="CharacterBody3D"]
transform = Transform3D(0.999983, 0.00579446, 0, -0.00579446, 0.999983, 0, 0, 0, 1, 0, 0.975222, 0)
material_override = SubResource("StandardMaterial3D_m6bjf")
radius = 0.492
[node name="UpperTorso" type="CSGSphere3D" parent="CharacterBody3D/Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.298181, 0)
radius = 0.001
[node name="CameraMount" type="Node3D" parent="CharacterBody3D/Body/UpperTorso"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0214237, -0.151336, -0.0131589)
[node name="Camera" type="Camera3D" parent="CharacterBody3D/Body/UpperTorso/CameraMount"]
transform = Transform3D(0.999902, 0.0139622, 0, -0.0139622, 0.999902, 0, 0, 0, 0.999999, 0, 0, 0)
current = true
script = ExtResource("3_gblkg")
[node name="Pistol" parent="CharacterBody3D/Body/UpperTorso/CameraMount/Camera" instance=ExtResource("4_xw0oh")]
transform = Transform3D(-0.999901, -0.0139622, -8.74142e-08, -0.0139621, 0.999901, -1.22061e-09, 8.74228e-08, 0, -1, 0.346313, -0.1921, -0.617977)
script = null
[node name="CollisionShape3D" type="CollisionShape3D" parent="CharacterBody3D"]
transform = Transform3D(2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0.981342, 0)
shape = SubResource("CylinderShape3D_1sre5")

28
scenes/weapon/bullet.gd Normal file
View File

@ -0,0 +1,28 @@
extends Node3D
const SPEED = 100
@onready var mesh = $MeshInstance3D
@onready var ray = $RayCast3D
@onready var particles = $GPUParticles3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
position += transform.basis * Vector3(0, 0, SPEED) * delta
ray.collision_mask = 1
ray.enabled = 1
if ray.is_colliding():
print("col")
mesh.visible = false
particles.emitting = true
await get_tree().create_timer(1.0).timeout
queue_free()
func _on_timer_timeout():
queue_free()

56
scenes/weapon/bullet.tscn Normal file
View File

@ -0,0 +1,56 @@
[gd_scene load_steps=7 format=3 uid="uid://b0agqeg53tey5"]
[ext_resource type="Script" path="res://scenes/weapon/bullet.gd" id="1_th28m"]
[sub_resource type="BoxMesh" id="BoxMesh_vxst2"]
size = Vector3(0.2, 0.2, 0.5)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_p8o05"]
albedo_color = Color(0.894987, 0.000702324, 0.905119, 1)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ynv38"]
albedo_color = Color(0.929412, 0, 0, 1)
emission_enabled = true
emission = Color(0.886321, 0.78611, 0.23507, 1)
emission_energy_multiplier = 7.71
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_58cgi"]
direction = Vector3(0, 0, 1)
spread = 22.5
initial_velocity_min = 3.47
initial_velocity_max = 5.0
gravity = Vector3(0, -19.6, 0)
linear_accel_min = -6.67
linear_accel_max = 6.67
[sub_resource type="BoxMesh" id="BoxMesh_mfkmi"]
size = Vector3(0.05, 0.05, 0.05)
[node name="Bullet" type="Node3D"]
script = ExtResource("1_th28m")
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(0.663102, 0, 0, 0, 0.601826, 0, 0, 0, 0.58984, 0, 0, 0)
mesh = SubResource("BoxMesh_vxst2")
surface_material_override/0 = SubResource("StandardMaterial3D_p8o05")
[node name="RayCast3D" type="RayCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.100459)
target_position = Vector3(0, 0, -0.5)
[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.18476)
material_override = SubResource("StandardMaterial3D_ynv38")
emitting = false
amount = 10
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_58cgi")
draw_pass_1 = SubResource("BoxMesh_mfkmi")
[node name="Timer" type="Timer" parent="."]
wait_time = 10.0
one_shot = true
autostart = true
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View File

@ -1,5 +1,11 @@
extends Node3D
var bullet = load("res://scenes/weapon/bullet.tscn")
var instance
@onready var gun_anim = $Pistol/DEAGLE/GunAnimation
#@onready var gun_barrel = $DEAGLE/CSGSphere3D
@onready var gun_barrel = $Pistol/DEAGLE/RayCast3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
@ -7,15 +13,16 @@ func _ready() -> void:
# TODO: Handle the shot logic
func shot():
var pistol := $DEAGLE
pistol.rotate_z(20.0)
var main_root = get_node("/root/TestMap")
if Input.is_action_pressed("shot"):
if !gun_anim.is_playing():
gun_anim.play("Shoot")
instance = bullet.instantiate()
instance.position = gun_barrel.global_position
instance.transform.basis = gun_barrel.global_transform.basis
get_tree().get_root().add_child(instance)
# 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

@ -1,9 +1,90 @@
[gd_scene load_steps=3 format=3 uid="uid://d21giy40pnjhe"]
[gd_scene load_steps=6 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="PackedScene" uid="uid://62jiwdcdnfwp" path="res://assets/models/weapon/DEAGLE/DEAGLE.glb" id="1_ard7n"]
[ext_resource type="Script" path="res://scenes/weapon/pistol.gd" id="1_jgbvq"]
[sub_resource type="Animation" id="Animation_7a114"]
length = 0.1
step = 0.01
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.03, 0.1),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(0, 0, -0.05), Vector3(0, 0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.03, 0.1),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(-0.872665, 0, 0), Vector3(0, 0, 0)]
}
[sub_resource type="Animation" id="Animation_48qgm"]
resource_name = "Shoot"
length = 0.1
step = 0.01
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath(".:position")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.02, 0.1),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(0, 0, -0.05), Vector3(0, 0, 0)]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath(".:rotation")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0, 0.02, 0.1),
"transitions": PackedFloat32Array(1, 1, 1),
"update": 0,
"values": [Vector3(0, 0, 0), Vector3(-0.698132, 0, 0), Vector3(0, 0, 0)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_6ael1"]
_data = {
"RESET": SubResource("Animation_7a114"),
"Shoot": SubResource("Animation_48qgm")
}
[node name="Pistol" type="Node3D"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
script = ExtResource("1_jgbvq")
[node name="DEAGLE" parent="." instance=ExtResource("1_ard7n")]
transform = Transform3D(0.678243, 0, 0, 0, 0.678243, 0, 0, 0, 0.678243, 0, 0, 0)
[node name="MuzzlePosition" type="Node3D" parent="DEAGLE"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.0979672, 0.226597)
[node name="GunAnimation" type="AnimationPlayer" parent="DEAGLE"]
libraries = {
"": SubResource("AnimationLibrary_6ael1")
}
[node name="RayCast3D" type="RayCast3D" parent="DEAGLE"]
transform = Transform3D(0.676274, 0, 0, 0, 0.676251, 0.00547663, 0, -0.00547663, 0.676251, 0, 0.0910377, 0.277056)
target_position = Vector3(0, 0, 1)
[node name="CSGSphere3D" type="CSGSphere3D" parent="DEAGLE"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0827075, 0.0943936, 0.248599)
radius = 0.001

View File

@ -39,8 +39,8 @@ 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"): $UpperTorso/Pistol.shot()
if Input.is_action_just_pressed("reload"): $UpperTorso/Pistol.reload()
if Input.is_action_just_pressed("shot"): $UpperTorso/ViewModelCamera.shot()
if Input.is_action_just_pressed("reload"): $Body/UpperTorso/CameraMount/Camera.reload()
if Input.is_action_just_pressed("crouch"): crouch()
if Input.is_action_just_released("crouch"): uncrouch()