12 Commits

19 changed files with 1703 additions and 50 deletions

View File

@ -13,6 +13,7 @@ config_version=5
config/name="Open Strike"
run/main_scene="res://scenes/utils/Menu.tscn"
config/features=PackedStringArray("4.3", "Forward Plus")
run/max_fps=120
config/icon="res://icon.svg"
[autoload]
@ -25,6 +26,7 @@ window/size/viewport_width=1920
window/size/viewport_height=1964
window/size/mode=4
window/size/borderless=true
window/vsync/vsync_mode=2
[filesystem]
@ -34,6 +36,7 @@ import/blender/enabled=false
body=""
target=""
player_placeholder=""
[input]

View File

@ -1,8 +1,10 @@
extends Node3D
var owner_placeholder: CharacterBody3D = null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
owner_placeholder = _get_owner()
pass # Replace with function body.
@ -12,5 +14,13 @@ func _process(delta: float) -> void:
func _on_head_collision_body_part_hit(dam: Variant) -> void:
print("head is hit")
#print("head is hit" + str(dam))
#print(owner_placeholder)
#if owner_placeholder.has_method("take_damage"):
owner_placeholder.take_damage(dam)
pass # Replace with function body.
func _get_owner() -> CharacterBody3D:
var owner_placeholder := find_parent("PlayerPlaceholder*")
return owner_placeholder

View File

@ -1048,7 +1048,7 @@ bones/24/name = "mixamorig_LeftHandRing2"
bones/24/parent = 23
bones/24/rest = Transform3D(1, 1.61871e-05, -9.45085e-08, -1.61871e-05, 1, 3.29224e-06, 9.45618e-08, -3.29224e-06, 1, 6.3543e-07, 3.60118, -1.47875e-05)
bones/24/enabled = true
bones/24/position = Vector3(-3.30613e-06, 3.60119, 1.50863e-07)
bones/24/position = Vector3(-3.30613e-06, 3.60119, 1.50864e-07)
bones/24/rotation = Quaternion(0.563924, -3.30111e-07, -0.0577891, 0.823803)
bones/24/scale = Vector3(1, 1, 1)
bones/25/name = "mixamorig_LeftHandRing3"
@ -1077,7 +1077,7 @@ bones/28/parent = 27
bones/28/rest = Transform3D(1, 0.000736602, -7.57697e-07, -0.000736602, 1, 9.24707e-06, 7.64508e-07, -9.24651e-06, 1, 1.0844e-06, 4.13666, 1.41886e-05)
bones/28/enabled = true
bones/28/position = Vector3(-9.08385e-06, 4.13665, 5.47372e-06)
bones/28/rotation = Quaternion(0.433129, -6.53828e-07, -0.0443853, 0.900239)
bones/28/rotation = Quaternion(0.433129, -6.53827e-07, -0.0443853, 0.900239)
bones/28/scale = Vector3(1, 1, 1)
bones/29/name = "mixamorig_LeftHandPinky3"
bones/29/parent = 28
@ -1126,7 +1126,7 @@ bones/35/parent = 34
bones/35/rest = Transform3D(0.894428, 0.447212, -8.12113e-07, -0.387297, 0.774597, -0.500001, -0.223606, 0.447215, 0.866025, 3.00297, 3.7888, 2.16716)
bones/35/enabled = true
bones/35/position = Vector3(3.00297, 3.7888, 2.16716)
bones/35/rotation = Quaternion(0.227577, -0.0598799, -0.162411, 0.958252)
bones/35/rotation = Quaternion(0.227577, -0.0598799, -0.162411, 0.958251)
bones/35/scale = Vector3(1, 1, 1)
bones/36/name = "mixamorig_RightHandThumb2"
bones/36/parent = 35
@ -1210,14 +1210,14 @@ bones/47/parent = 34
bones/47/rest = Transform3D(1, 9.66599e-06, -1.40744e-07, -9.66599e-06, 1, -2.81994e-06, 1.40717e-07, 2.81994e-06, 1, -2.21663, 12.147, -0.00999829)
bones/47/enabled = true
bones/47/position = Vector3(-2.21664, 12.147, -0.00998812)
bones/47/rotation = Quaternion(0.0911117, 0.11369, 0.100504, 0.984211)
bones/47/rotation = Quaternion(0.0911117, 0.11369, 0.100504, 0.984212)
bones/47/scale = Vector3(1, 1, 1)
bones/48/name = "mixamorig_RightHandRing2"
bones/48/parent = 47
bones/48/rest = Transform3D(1, -1.60845e-05, 3.26056e-09, 1.60845e-05, 1, 1.32059e-06, -3.2818e-09, -1.32059e-06, 1, -2.50026e-07, 3.6012, -7.75122e-07)
bones/48/enabled = true
bones/48/position = Vector3(-2.50026e-07, 3.6012, -7.75122e-07)
bones/48/rotation = Quaternion(0.836665, 8.70473e-07, 0.068157, 0.543457)
bones/48/rotation = Quaternion(0.836665, 8.70474e-07, 0.068157, 0.543457)
bones/48/scale = Vector3(1, 1, 1)
bones/49/name = "mixamorig_RightHandRing3"
bones/49/parent = 48
@ -1301,14 +1301,14 @@ bones/60/parent = 0
bones/60/rest = Transform3D(-0.999981, -0.00611455, -7.52684e-05, 0.00611501, -0.999901, -0.0126672, 2.1931e-06, -0.0126674, 0.99992, -9.12503, -6.6556, -0.0553527)
bones/60/enabled = true
bones/60/position = Vector3(-9.12503, -6.6556, -0.0553527)
bones/60/rotation = Quaternion(-0.0339456, 0.334676, 0.92684, -0.166754)
bones/60/rotation = Quaternion(-0.0339455, 0.334676, 0.92684, -0.166754)
bones/60/scale = Vector3(1, 1, 1)
bones/61/name = "mixamorig_RightLeg"
bones/61/parent = 60
bones/61/rest = Transform3D(0.99993, -0.0118315, -0.000580536, 0.0118448, 0.999271, 0.0362854, 0.000150802, -0.0362897, 0.999341, 3.28565e-07, 40.5995, 1.49012e-08)
bones/61/enabled = true
bones/61/position = Vector3(3.28565e-07, 40.5995, 1.49012e-08)
bones/61/rotation = Quaternion(-0.581827, -0.0846291, -0.0166473, 0.808727)
bones/61/rotation = Quaternion(-0.581827, -0.0846291, -0.0166473, 0.808726)
bones/61/scale = Vector3(1, 1, 1)
bones/62/name = "mixamorig_RightFoot"
bones/62/parent = 61

View File

@ -1,13 +1,13 @@
extends Area3D
@export var damage: int = 100
@export var damage: int = 20
signal body_part_hit(dam)
# 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: float) -> void:
pass

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://b10lpwfjgxds4"]
[gd_scene load_steps=11 format=3 uid="uid://b10lpwfjgxds4"]
[ext_resource type="Script" path="res://scripts/player/player_input_controller.gd" id="1_q75ai"]
[ext_resource type="Texture2D" uid="uid://oopj5mj1vdp0" path="res://assets/crosshairs/crosshair_default.png" id="2_lsd7c"]
@ -14,6 +14,19 @@ properties/0/replication_mode = 1
properties/1/path = NodePath(".:rotation")
properties/1/spawn = true
properties/1/replication_mode = 1
properties/2/path = NodePath(".:health")
properties/2/spawn = true
properties/2/replication_mode = 2
properties/3/path = NodePath("FirstPersonCameraMount/HUD/HealthIndicator:text")
properties/3/spawn = true
properties/3/replication_mode = 2
[sub_resource type="LabelSettings" id="LabelSettings_toaij"]
font_size = 70
[sub_resource type="LabelSettings" id="LabelSettings_1j1uq"]
font_size = 100
font_color = Color(0.756874, 0, 0.223924, 1)
[sub_resource type="Animation" id="Animation_falg4"]
length = 0.001
@ -85,26 +98,27 @@ shape = SubResource("CapsuleShape3D_jc50w")
replication_config = SubResource("SceneReplicationConfig_tl74a")
[node name="FirstPersonCameraMount" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.609154, 0)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.609154, -0.209324)
[node name="Camera" type="Camera3D" parent="FirstPersonCameraMount"]
fov = 40.0
[node name="BulletStartingPoint" type="Node3D" parent="FirstPersonCameraMount"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, -0.42185)
[node name="SubViewportContainer" type="SubViewportContainer" parent="FirstPersonCameraMount/Camera"]
visible = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
stretch = true
[node name="AimRay" type="RayCast3D" parent="FirstPersonCameraMount/BulletStartingPoint"]
target_position = Vector3(0, 0, 1000)
hit_from_inside = true
[node name="SubViewport" type="SubViewport" parent="FirstPersonCameraMount/Camera/SubViewportContainer"]
transparent_bg = true
handle_input_locally = false
size = Vector2i(1920, 1964)
render_target_update_mode = 0
[node name="GunMount" type="Node3D" parent="FirstPersonCameraMount"]
[node name="AnimationPlayer" type="AnimationPlayer" parent="FirstPersonCameraMount/GunMount"]
libraries = {
"": SubResource("AnimationLibrary_u1b6p")
}
[node name="HUD" type="Control" parent="FirstPersonCameraMount"]
[node name="HUD" type="Control" parent="FirstPersonCameraMount/Camera/SubViewportContainer/SubViewport"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@ -115,7 +129,7 @@ grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
[node name="TextureRect" type="TextureRect" parent="FirstPersonCameraMount/HUD"]
[node name="TextureRect" type="TextureRect" parent="FirstPersonCameraMount/Camera/SubViewportContainer/SubViewport/HUD"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
@ -130,5 +144,38 @@ grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("2_lsd7c")
[node name="HealthIndicator" type="Label" parent="FirstPersonCameraMount/Camera/SubViewportContainer/SubViewport/HUD"]
layout_mode = 1
anchors_preset = 2
anchor_top = 1.0
anchor_bottom = 1.0
offset_top = -23.0
offset_right = 40.0
grow_vertical = 0
text = "100"
label_settings = SubResource("LabelSettings_toaij")
[node name="FPS" type="Label" parent="FirstPersonCameraMount/Camera/SubViewportContainer/SubViewport/HUD" groups=["player_placeholder"]]
layout_mode = 1
offset_right = 40.0
offset_bottom = 23.0
text = "0"
label_settings = SubResource("LabelSettings_1j1uq")
[node name="BulletStartingPoint" type="Node3D" parent="FirstPersonCameraMount"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, -0.42185)
[node name="AimRay" type="RayCast3D" parent="FirstPersonCameraMount/BulletStartingPoint"]
target_position = Vector3(0, 0, 1000)
hit_from_inside = true
collide_with_areas = true
[node name="GunMount" type="Node3D" parent="FirstPersonCameraMount"]
[node name="AnimationPlayer" type="AnimationPlayer" parent="FirstPersonCameraMount/GunMount"]
libraries = {
"": SubResource("AnimationLibrary_u1b6p")
}
[node name="ModelMount" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.790262, 0)

View File

@ -2,8 +2,15 @@ extends CSGBox3D
var health = 5
@export var color: Color = Color(0, 0, 0)
var colors = [Color(1.0, 0.0, 0.0, 1.0),
Color(0.0, 1.0, 0.0, 1.0),
Color(0.0, 0.0, 1.0, 0.0)]
func take_damage():
health -= 1
color = Color(randf(), randf(), randf())
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
@ -11,5 +18,6 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
material_override.albedo_color = color
if health < 1:
queue_free()

View File

@ -16,9 +16,9 @@ func _ready() -> void:
if multiplayer.is_server():
for i in GameServerManager.players:
char = ResourceLoader.load("res://scenes/characters/placeholder.tscn").instantiate()
char.name = str(GameServerManager.players[i].name)
char.name = "PlayerPlaceholder_" + str(GameServerManager.players[i].name)
char.global_position = position
var my_random_number = RandomNumberGenerator.new().randf_range(0.0, 5.0)
var my_random_number = RandomNumberGenerator.new().randf_range(0.0, 20.0)
char.global_position = position
char.global_position.x += my_random_number
char.global_position.y += 300 + my_random_number
@ -26,7 +26,16 @@ func _ready() -> void:
$MultiplayerSpawner.spawn(char)
players.add_child(char)
var bullet_amount: int = 0
func spawn_bullet(position):
print("spawning a bullet")
var node: Node3D = ResourceLoader.load("res://scenes/weapon/bullet.tscn").instantiate()
node.position = position.global_position
node.transform.basis = position.global_transform.basis
node.name = str(bullet_amount)
bullet_amount += 1
$BulletSpawner.spawn(node)
$Bullets.add_child(node)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,11 @@
extends CSGBox3D
# 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: float) -> void:
pass

View File

@ -0,0 +1,16 @@
extends SubViewportContainer
var current_player_placeholder: Node3D = null
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#current_player_placeholder = GameServerManager.get_current_player_placeholder()
pass # Replace with function body.
@onready var health_indicator: Label = $SubViewport/HUD/HealthIndicator
@onready var fps_indicator: Label = $SubViewport/HUD/FPS
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
#if current_player_placeholder:
#health_indicator.text = str(current_player_placeholder.health)
#fps_indicator.text = str(Engine.get_frames_per_second())
pass

View File

@ -35,6 +35,14 @@ offset_right = 224.0
offset_bottom = 220.0
text = "Join"
[node name="TextEdit" type="TextEdit" parent="."]
layout_mode = 0
offset_left = 238.0
offset_top = 151.0
offset_right = 497.0
offset_bottom = 220.0
text = "127.0.0.1"
[connection signal="player_connected" from="." to="." method="_on_player_connected"]
[connection signal="player_disconnected" from="." to="." method="_on_player_disconnected"]
[connection signal="server_disconnected" from="." to="." method="_on_server_disconnected"]

View File

@ -10,7 +10,7 @@ signal server_disconnected
const PORT = 7000
const DEFAULT_SERVER_IP = "127.0.0.1" # IPv4 localhost
const MAX_CONNECTIONS = 20
@onready var address_input: TextEdit = $TextEdit
var players = {}
var my_random_number = RandomNumberGenerator.new().randf_range(-2.0, 2.0)
var player_info = {"name": str(my_random_number)}
@ -25,8 +25,7 @@ func _ready() -> void:
multiplayer.server_disconnected.connect(_on_server_disconnected)
func join_game(address = ""):
if address.is_empty():
address = DEFAULT_SERVER_IP
address = address_input.text
var peer = ENetMultiplayerPeer.new()
var error = peer.create_client(address, PORT)
if error:

View File

@ -1,6 +1,6 @@
extends Node3D
const SPEED = 715
const SPEED = 200 # 200
@onready var mesh = $RigidBody3D/MeshInstance3D
@onready var rigid_body_3d: RigidBody3D = $RigidBody3D
@ -14,12 +14,20 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
var time_per_frame: float = 1 / Engine.get_frames_per_second()
var distance: float = time_per_frame * SPEED * 1.5
ray.target_position.z = distance
position += transform.basis * Vector3(0, 0, SPEED) * delta
rigid_body_3d.set_use_continuous_collision_detection(true)
#ray.collision_mask = 1
#ray.enabled = 1
ray.target_position.z = SPEED / Engine.get_frames_per_second()
if ray.is_colliding():
var collider = ray.get_collider()
if collider != null and collider.is_in_group("target"):
ray.get_collider().take_damage()
if collider != null and collider.is_in_group("body"):
print(collider)
ray.get_collider().hit()
rigid_body_3d.visible = false
particles.emitting = true
#if ray.get_collider().is_in_group("body"):

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=3 uid="uid://b0agqeg53tey5"]
[gd_scene load_steps=9 format=3 uid="uid://b0agqeg53tey5"]
[ext_resource type="Script" path="res://scenes/weapon/bullet.gd" id="1_th28m"]
@ -30,7 +30,16 @@ linear_accel_max = 6.67
[sub_resource type="BoxMesh" id="BoxMesh_mfkmi"]
size = Vector3(0.05, 0.05, 0.05)
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_b8q4c"]
properties/0/path = NodePath(".:position")
properties/0/spawn = true
properties/0/replication_mode = 2
properties/1/path = NodePath(".:rotation")
properties/1/spawn = true
properties/1/replication_mode = 2
[node name="Bullet" type="Node3D"]
transform = Transform3D(20, 0, 0, 0, 20, 0, 0, 0, 20, 0, 0, 0)
script = ExtResource("1_th28m")
[node name="RigidBody3D" type="RigidBody3D" parent="."]
@ -62,11 +71,14 @@ shape = SubResource("CylinderShape3D_l3sdq")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.18476)
material_override = SubResource("StandardMaterial3D_ynv38")
emitting = false
amount = 10
amount = 100
lifetime = 6.29
one_shot = true
explosiveness = 1.0
process_material = SubResource("ParticleProcessMaterial_58cgi")
draw_pass_1 = SubResource("BoxMesh_mfkmi")
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_b8q4c")
[connection signal="timeout" from="RigidBody3D/Timer" to="." method="_on_timer_timeout"]

View File

@ -1,6 +1,6 @@
extends Node3D
const SPEED = 715
const SPEED = 10
@onready var mesh = $Object_10

View File

@ -1,5 +1,6 @@
extends MeshInstance3D
var alpha = 1.0
func init(pos1, pos2):
var draw_mesh := ImmediateMesh.new()
mesh = draw_mesh
@ -10,12 +11,15 @@ func init(pos1, pos2):
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
var dup_material = material_override.duplicate()
material_override = dup_material
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
alpha -= delta * 3.5
material_override.albedo_color.a = alpha
func _on_timer_timeout() -> void:

View File

@ -3,9 +3,11 @@
[ext_resource type="Script" path="res://scenes/weapon/misc/bullet_trail_generic.gd" id="1_k8eg1"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ybqvs"]
albedo_color = Color(0.934388, 0.967243, 0.955863, 1)
emission = Color(1, 1, 1, 1)
emission_energy_multiplier = 2.7
transparency = 1
albedo_color = Color(0.917767, 0.596302, 0, 1)
emission_enabled = true
emission = Color(0.454139, 0.861507, 0, 1)
emission_energy_multiplier = 4.0
[node name="BulletTrailGeneric" type="MeshInstance3D"]
material_override = SubResource("StandardMaterial3D_ybqvs")

View File

@ -1,6 +1,16 @@
extends Node
var players = {}
#func get_current_player_placeholder() -> Node3D:
#var id = str(multiplayer.get_unique_id())
#print(id)
#var root: Window = get_tree().get_root()
#var placeholder = root.find_child("_" + id)
#print(placeholder)
#return placeholder
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.

View File

@ -3,7 +3,7 @@
# ---------------------------------------------------------------------
class_name PlayerInput extends CharacterBody3D
var health: int = 100
@export var health: int = 100
@export_category("PlayerInput")
@ -38,6 +38,10 @@ func _ready() -> void:
var err := _add_first_view_model()
if err != OK:
print("Error occured: " + str(err))
err = _add_legs_to_first_view()
if err != OK:
print("Error occured: " + str(err))
_enable_camera()
else:
var err := _add_world_model()
@ -64,6 +68,7 @@ var current_gun: String = "ak"
@onready var gun_mount: Node3D = $FirstPersonCameraMount/GunMount
@onready var gun_mount_anim: AnimationPlayer = $FirstPersonCameraMount/GunMount/AnimationPlayer
var gun_with_hands: Node3D = null
# -- Add the first person view to pthe player
func _add_first_view_model() -> Error :
# -- TODO: It should not be hardcoded
@ -82,6 +87,30 @@ func _add_first_view_model() -> Error :
gun_mount.add_child(node)
return OK
var first_view_legs_anim: AnimationPlayer = null
# -- Add a world model to the player, that should be seen by other players
# -- on the server
func _add_legs_to_first_view() -> Error :
# -- TODO: It should not be hardcoded
var path := "res://scenes/characters/blue/dummy.tscn"
if not ResourceLoader.exists(path):
return ERR_DOES_NOT_EXIST
var scene: PackedScene = ResourceLoader.load(path)
if not scene.can_instantiate():
return ERR_CANT_OPEN
var node: Node3D = scene.instantiate()
var skeleton: Skeleton3D = node.find_child("Skeleton3D")
var bone := skeleton.find_bone("mixamorig_Spine")
if bone != -1:
skeleton.set_bone_pose_scale(bone, Vector3(0, 0, 0))
model_mount.add_child(node)
var animation_node: AnimationPlayer = node.find_child("AnimationPlayer")
if animation_node != null:
first_view_legs_anim = animation_node
return OK
func _enable_camera():
first_view_camera.make_current()
@ -130,6 +159,14 @@ func _rotate_camera(sens_mod: float = 1.0) -> void:
rotation.y -= look_dir.x * camera_sens * sens_mod
first_view_camera_mount.rotation.x = clamp(first_view_camera_mount.rotation.x - look_dir.y * camera_sens * sens_mod, -1.5, 1.5)
@onready var health_indicator = $FirstPersonCameraMount/Camera/SubViewportContainer/SubViewport/HUD/HealthIndicator
@onready var fps_indicator = $FirstPersonCameraMount/Camera/SubViewportContainer/SubViewport/HUD/FPS
func _process(delta: float) -> void:
health_indicator.text = str(health)
fps_indicator.text = str(Engine.get_frames_per_second())
if health == 0:
queue_free()
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
@ -148,11 +185,15 @@ func _physics_process(delta: float) -> void:
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
gun_mount_anim.play("move")
if first_view_legs_anim != null:
first_view_legs_anim.play("Run Forward")
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
else:
if gun_mount_anim.is_playing():
gun_mount_anim.stop()
if first_view_legs_anim != null and first_view_legs_anim.is_playing():
first_view_legs_anim.stop()
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
@ -164,13 +205,27 @@ var bullet = load("res://scenes/weapon/bullet.tscn")
@onready var bullet_starting_point: Node3D = $FirstPersonCameraMount/BulletStartingPoint
@onready var aim_ray: RayCast3D = $FirstPersonCameraMount/BulletStartingPoint/AimRay
# --find the gun node and exec shoot
var cant_shoot: bool = false
func _shoot():
if not cant_shoot:
_send_shot_to_server.rpc_id(1, aim_ray.global_position)
if aim_ray.is_colliding():
var collider := aim_ray.get_collider()
if collider != null and collider.is_in_group("target"):
aim_ray.get_collider().take_damage()
if collider != null and collider.is_in_group("body"):
collider.hit()
var root := get_tree().get_root()
gun_with_hands.shoot()
cant_shoot = true
await get_tree().create_timer(0.2).timeout
cant_shoot = false
@rpc("any_peer", "call_local", "unreliable_ordered")
func _send_shot_to_server(start_position):
# -- TODO: Should not be hardcoded
var world: Node3D = find_parent("ElTest")
world.spawn_bullet(bullet_starting_point)
func _get_camera_collision():
var viewport = get_viewport().size
@ -198,3 +253,8 @@ func _hit_scan_collision(collision_point):
func _hit_scan_damage(Collider):
#if Collider.is_in_group("target") and Collider.has_method("take_damage"):
print("damaged")
func take_damage(dam: int):
print("damage")
health -= dam
print(health)