Firing is now from the gun itself + bugfixes

This commit is contained in:
leca 2024-02-24 20:11:41 +03:00
parent 25405cf9b5
commit 18471e74ec
9 changed files with 115 additions and 11 deletions

View File

@ -7,3 +7,7 @@ transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, -0.570068, 0, 0)
[node name="automatto" parent="." instance=ExtResource("1_kapkd")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.18626, -1.25157, 0)
[node name="raycast" type="RayCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.92407, 0.951779, 0)
target_position = Vector3(-1, 0, 0)

BIN
models/buddy.glb Normal file

Binary file not shown.

34
models/buddy.glb.import Normal file
View File

@ -0,0 +1,34 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://coa22cxx7aoe1"
path="res://.godot/imported/buddy.glb-6b88d2f9ceb79cd70c33a24352eb18ce.scn"
[deps]
source_file="res://models/buddy.glb"
dest_files=["res://.godot/imported/buddy.glb-6b88d2f9ceb79cd70c33a24352eb18ce.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 1010 KiB

View File

@ -0,0 +1,36 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dirdtjfuc7ibi"
path.s3tc="res://.godot/imported/buddy_1613124237_95-p-fon-kozha-zheltaya-205.jpg-85dd45775a662112c983877a89c4d254.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
generator_parameters={}
[deps]
source_file="res://models/buddy_1613124237_95-p-fon-kozha-zheltaya-205.jpg"
dest_files=["res://.godot/imported/buddy_1613124237_95-p-fon-kozha-zheltaya-205.jpg-85dd45775a662112c983877a89c4d254.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
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=0

View File

@ -6,3 +6,7 @@
[node name="pistoletto" parent="." instance=ExtResource("1_hdcb6")]
transform = Transform3D(0.21, 0, 0, 0, 0.21, 0, 0, 0, 0.21, 0, 0, 0)
[node name="raycast" type="RayCast3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.461124, 0.0946267, 2.01564e-08)
target_position = Vector3(-1, 0, 0)

View File

@ -1,11 +1,9 @@
[gd_scene load_steps=8 format=3 uid="uid://b2jhgtduapovl"]
[gd_scene load_steps=7 format=3 uid="uid://b2jhgtduapovl"]
[ext_resource type="Script" path="res://scripts/Player.gd" id="1_o6o4b"]
[ext_resource type="PackedScene" uid="uid://cnu1vf8k5i3tv" path="res://models/pistol.tscn" id="2_nxbij"]
[ext_resource type="PackedScene" uid="uid://caos4gg5cd6f6" path="res://models/ak_47.tscn" id="3_r56e3"]
[sub_resource type="CylinderMesh" id="CylinderMesh_hyaut"]
[sub_resource type="SphereMesh" id="SphereMesh_fp0bl"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_yyp7b"]
@ -23,14 +21,9 @@ script = ExtResource("1_o6o4b")
[node name="Camera" type="Camera3D" parent="CharacterBody3D/Head"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.675496, 0)
[node name="RayCast3D" type="RayCast3D" parent="CharacterBody3D/Head/Camera"]
[node name="viewRaycast" type="RayCast3D" parent="CharacterBody3D/Head/Camera"]
target_position = Vector3(0, 0, -100)
[node name="point" type="MeshInstance3D" parent="CharacterBody3D/Head/Camera"]
transform = Transform3D(0.368235, 0, 0, 0, -4.37934e-08, -0.354994, 0, 1.00188, -1.55173e-08, 0, -0.0134474, -0.57695)
mesh = SubResource("CylinderMesh_hyaut")
skeleton = NodePath("../..")
[node name="Hand" type="Node3D" parent="CharacterBody3D/Head/Camera"]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.72454, -0.463491, -0.808041)
@ -39,7 +32,10 @@ transform = Transform3D(0.16, 0, 0, 0, 0.16, 0, 0, 0, 0.16, 0, 0, 0)
visible = false
mesh = SubResource("SphereMesh_fp0bl")
[node name="raycast" type="RayCast3D" parent="CharacterBody3D/Head/Camera/Hand/knife"]
[node name="pistol" parent="CharacterBody3D/Head/Camera/Hand" instance=ExtResource("2_nxbij")]
transform = Transform3D(1, 0, -3.55271e-15, 0, 1, 0, 3.55271e-15, 0, 1, 0, 0, 0)
visible = false
[node name="ak-47" parent="CharacterBody3D/Head/Camera/Hand" instance=ExtResource("3_r56e3")]

View File

@ -131,6 +131,7 @@ func client_ready(client_id):
clients[client_id]["ready"] = true
var client_cb3d = find_cb3d_by_internal_id(internal_id)
var class_spawnpoint = find_class_type_by_number(client["class_type"])["spawnpoint"]
client_cb3d.set_properties(client)
client_cb3d.teleport.rpc_id(client_id, Vector3(class_spawnpoint[0], class_spawnpoint[1], class_spawnpoint[2]))
func _Peer_Disconnected(client_id):
@ -187,12 +188,29 @@ func shot(client_id):
var current_weapon = settings["game"]["weapons"].find_key(find_weapon_by_number(client["current_weapon"]["number"]))
var current_weapon_settings = settings["game"]["weapons"][current_weapon]
var raycast:RayCast3D = find_cb3d_by_internal_id(internal_id).get_node("Head/Camera/RayCast3D")
#var view_raycast:RayCast3D = find_cb3d_by_internal_id(internal_id).get_node("Head/Camera/viewRaycast")
#var raycast:RayCast3D = find_cb3d_by_internal_id(internal_id).get_node("Head/Camera/viewRaycast")
#var weapon_raycast:RayCast3D = find_cb3d_by_internal_id(internal_id).get_node("Head/Camera/Hand/" + str(current_weapon) + "/raycast")
print(current_weapon)
var client_cb3d = find_cb3d_by_internal_id(internal_id)
var raycast:RayCast3D = client_cb3d.get_node("Head/Camera/viewRaycast")
var weapon_raycast:RayCast3D = client_cb3d.get_node("Head/Camera/Hand/" + str(current_weapon) + "/raycast")
raycast.target_position.z = -current_weapon_settings["range"]
raycast.force_raycast_update()
raycast.force_update_transform()
var target_point = raycast.get_collision_point()
var target = raycast.get_collider()
weapon_raycast.target_position = weapon_raycast.to_local(target_point) #- weapon_raycast.position)
weapon_raycast.get_node("..").rotation.y = - atan((weapon_raycast.position.x - client_cb3d.position.x) / ((-current_weapon_settings["range"]) - (abs(weapon_raycast.position.z - client_cb3d.position.z))))
#weapon_raycast.target_position = weapon_raycast.to_local(raycast.to_global(raycast.target_position) - weapon_raycast.position)
weapon_raycast.target_position.y += current_weapon_settings["spreading"] * randf() * sin(randf() * 2 * PI)
weapon_raycast.target_position.z += current_weapon_settings["spreading"] * randf() * cos(randf() * 2 * PI)
print(str(weapon_raycast.target_position))
weapon_raycast.force_raycast_update()
weapon_raycast.force_update_transform()
var target = weapon_raycast.get_collider()
if (not target is CharacterBody3D): return
var target_internal_id = int(target.get_node("..").name.get_slice("player", 1))
var target_client

View File

@ -53,8 +53,10 @@ var healthBar
var ammoLabel
var magazineLabel
var statusLabel
func set_properties(props):
properties = props
$"Head/Nickname".text = properties["nickname"]
$"..".name = "player" + str(properties["internal_id"])
if (game_settings != null):
change_weapon(properties["current_weapon"]["number"])
@ -112,6 +114,15 @@ func _ready():
playerCharacterBody.up_direction = Vector3.UP;
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func update_weapon_raycast():
print(str(Weapons))
var current_weapon_name = Weapons.find_key(properties["current_weapon"])
print(current_weapon_name)
if(current_weapon_name == null): current_weapon_name = "knife"
var raycast:RayCast3D = get_node("Head/Camera/viewRaycast")
var weapon_raycast:RayCast3D = get_node("Head/Camera/Hand/" + str(current_weapon_name) + "/raycast")
weapon_raycast.target_position = weapon_raycast.to_local(raycast.to_global(raycast.target_position) - weapon_raycast.position)
func try_shoot():
var current_weapon = game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"]))
@ -177,6 +188,7 @@ func _physics_process(delta):
try_shoot()
update_hud()
update_weapon_raycast()
if Input.is_action_just_pressed("reload"):
var current_weapon = game_settings["weapons"].find_key(find_weapon_by_number(properties["current_weapon"]["number"]))