WIP: Spawn bullets on the server and sync them
This commit is contained in:
parent
66efa9ec99
commit
c2a5f9cf1c
@ -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]
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=10 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"]
|
||||
@ -75,6 +75,10 @@ _data = {
|
||||
[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)
|
||||
|
||||
[node name="CharacterPlaceholder" type="CharacterBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.799455, 0)
|
||||
collision_layer = 9
|
||||
@ -145,5 +149,12 @@ grow_vertical = 0
|
||||
text = "100"
|
||||
label_settings = SubResource("LabelSettings_toaij")
|
||||
|
||||
[node name="FPS" type="Label" parent="FirstPersonCameraMount/HUD"]
|
||||
layout_mode = 1
|
||||
offset_right = 40.0
|
||||
offset_bottom = 23.0
|
||||
text = "0"
|
||||
label_settings = SubResource("LabelSettings_1j1uq")
|
||||
|
||||
[node name="ModelMount" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.790262, 0)
|
||||
|
@ -1,6 +1,6 @@
|
||||
extends Node3D
|
||||
|
||||
const SPEED = 2
|
||||
const SPEED = 200 # 200
|
||||
|
||||
@onready var mesh = $RigidBody3D/MeshInstance3D
|
||||
@onready var rigid_body_3d: RigidBody3D = $RigidBody3D
|
||||
@ -14,12 +14,15 @@ 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():
|
||||
print("I got hit")
|
||||
rigid_body_3d.visible = false
|
||||
particles.emitting = true
|
||||
#if ray.get_collider().is_in_group("body"):
|
||||
|
@ -36,7 +36,7 @@ properties/0/spawn = true
|
||||
properties/0/replication_mode = 2
|
||||
properties/1/path = NodePath(".:rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 0
|
||||
properties/1/replication_mode = 2
|
||||
|
||||
[node name="Bullet" type="Node3D"]
|
||||
transform = Transform3D(20, 0, 0, 0, 20, 0, 0, 0, 20, 0, 0, 0)
|
||||
@ -71,7 +71,7 @@ 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
|
||||
|
@ -160,8 +160,10 @@ func _rotate_camera(sens_mod: float = 1.0) -> void:
|
||||
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/HUD/HealthIndicator
|
||||
@onready var fps_indicator = $FirstPersonCameraMount/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()
|
||||
|
||||
@ -203,16 +205,21 @@ 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():
|
||||
_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()
|
||||
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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user