movement sync
This commit is contained in:
parent
daa83ce96d
commit
bb3a14ece7
13 changed files with 46 additions and 35 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
[gd_scene load_steps=24 format=3 uid="uid://cqrh2cc7m2i7f"]
|
[gd_scene load_steps=24 format=3 uid="uid://cqrh2cc7m2i7f"]
|
||||||
|
|
||||||
[ext_resource type="Environment" uid="uid://d0cfgtx2yxw13" path="res://environments/prototype_environment.tres" id="1_i6jab"]
|
[ext_resource type="Environment" uid="uid://d0cfgtx2yxw13" path="res://environments/prototype_environment.tres" id="1_i6jab"]
|
||||||
[ext_resource type="Script" uid="uid://ypgm3aplt78m" path="res://scripts/multiplayer/team_spawner.gd" id="4_pi0y7"]
|
[ext_resource type="Script" uid="uid://ypgm3aplt78m" path="res://scripts/multiplayer/spawn_system/team_spawner.gd" id="4_pi0y7"]
|
||||||
[ext_resource type="Material" uid="uid://bx3f5vx71ynh5" path="res://materials/Graymat.tres" id="4_y6i55"]
|
[ext_resource type="Material" uid="uid://bx3f5vx71ynh5" path="res://materials/Graymat.tres" id="4_y6i55"]
|
||||||
[ext_resource type="Material" uid="uid://dynpcduei1wfn" path="res://materials/Bluemat.tres" id="4_yx0ab"]
|
[ext_resource type="Material" uid="uid://dynpcduei1wfn" path="res://materials/Bluemat.tres" id="4_yx0ab"]
|
||||||
[ext_resource type="Material" uid="uid://mlha6r17v2en" path="res://materials/DarkBluemat.tres" id="5_bno23"]
|
[ext_resource type="Material" uid="uid://mlha6r17v2en" path="res://materials/DarkBluemat.tres" id="5_bno23"]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=80 format=4 uid="uid://dpsr6ug3pkb40"]
|
[gd_scene load_steps=82 format=4 uid="uid://dpsr6ug3pkb40"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://3dphlay25fih" path="res://scripts/player/player.gd" id="1_g2els"]
|
[ext_resource type="Script" uid="uid://3dphlay25fih" path="res://scripts/player/player.gd" id="1_g2els"]
|
||||||
[ext_resource type="Script" uid="uid://dalwlndejfdhm" path="res://scripts/player/crosshair.gd" id="3_dqkch"]
|
[ext_resource type="Script" uid="uid://dalwlndejfdhm" path="res://scripts/player/crosshair.gd" id="3_dqkch"]
|
||||||
|
|
@ -36,6 +36,7 @@
|
||||||
[ext_resource type="Script" uid="uid://b2djbdh05pbcn" path="res://scripts/player/team_color_switcher.gd" id="25_1mtds"]
|
[ext_resource type="Script" uid="uid://b2djbdh05pbcn" path="res://scripts/player/team_color_switcher.gd" id="25_1mtds"]
|
||||||
[ext_resource type="Material" uid="uid://cjb0h3of85nc2" path="res://materials/players/molikman/mat_Molikman.tres" id="26_r2jxp"]
|
[ext_resource type="Material" uid="uid://cjb0h3of85nc2" path="res://materials/players/molikman/mat_Molikman.tres" id="26_r2jxp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://15mf4452fse0" path="res://textures/players/molikman/molikman_ingame_Molikman_blue.png" id="27_j3w78"]
|
[ext_resource type="Texture2D" uid="uid://15mf4452fse0" path="res://textures/players/molikman/molikman_ingame_Molikman_blue.png" id="27_j3w78"]
|
||||||
|
[ext_resource type="Script" uid="uid://dfvnx8f1v6m5g" path="res://scripts/multiplayer/player_input.gd" id="37_b2eak"]
|
||||||
|
|
||||||
[sub_resource type="ArrayMesh" id="ArrayMesh_lot4n"]
|
[sub_resource type="ArrayMesh" id="ArrayMesh_lot4n"]
|
||||||
_surfaces = [{
|
_surfaces = [{
|
||||||
|
|
@ -7413,15 +7414,21 @@ properties/0/replication_mode = 1
|
||||||
properties/1/path = NodePath(".:rotation")
|
properties/1/path = NodePath(".:rotation")
|
||||||
properties/1/spawn = true
|
properties/1/spawn = true
|
||||||
properties/1/replication_mode = 1
|
properties/1/replication_mode = 1
|
||||||
properties/2/path = NodePath("Camera3D:rotation")
|
properties/2/path = NodePath(".:hp")
|
||||||
properties/2/spawn = true
|
properties/2/spawn = true
|
||||||
properties/2/replication_mode = 1
|
properties/2/replication_mode = 1
|
||||||
properties/3/path = NodePath(".:hp")
|
properties/3/path = NodePath(".:team")
|
||||||
properties/3/spawn = true
|
properties/3/spawn = true
|
||||||
properties/3/replication_mode = 1
|
properties/3/replication_mode = 2
|
||||||
properties/4/path = NodePath(".:team")
|
properties/4/path = NodePath(".:player_id")
|
||||||
properties/4/spawn = true
|
properties/4/spawn = true
|
||||||
properties/4/replication_mode = 2
|
properties/4/replication_mode = 0
|
||||||
|
properties/5/path = NodePath(".:collision_layer")
|
||||||
|
properties/5/spawn = true
|
||||||
|
properties/5/replication_mode = 0
|
||||||
|
properties/6/path = NodePath(".:collision_mask")
|
||||||
|
properties/6/spawn = true
|
||||||
|
properties/6/replication_mode = 0
|
||||||
|
|
||||||
[sub_resource type="Curve" id="Curve_fbysy"]
|
[sub_resource type="Curve" id="Curve_fbysy"]
|
||||||
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 2.5229826, 0.0, 0, 0]
|
_data = [Vector2(0, 0), 0.0, 0.0, 0, 0, Vector2(1, 1), 2.5229826, 0.0, 0, 0]
|
||||||
|
|
@ -7604,6 +7611,11 @@ _data = {
|
||||||
radius = 0.82177734
|
radius = 0.82177734
|
||||||
height = 3.7087402
|
height = 3.7087402
|
||||||
|
|
||||||
|
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_5amik"]
|
||||||
|
properties/0/path = NodePath("PlayerInput:direction")
|
||||||
|
properties/0/spawn = true
|
||||||
|
properties/0/replication_mode = 1
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_models")]
|
[node name="Player" type="CharacterBody3D" node_paths=PackedStringArray("weapon_models")]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
collision_mask = 3
|
collision_mask = 3
|
||||||
|
|
@ -8701,7 +8713,7 @@ grow_vertical = 2
|
||||||
visible = false
|
visible = false
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
[node name="PlayerPropertiesSync" type="MultiplayerSynchronizer" parent="."]
|
||||||
replication_config = SubResource("SceneReplicationConfig_qhqgy")
|
replication_config = SubResource("SceneReplicationConfig_qhqgy")
|
||||||
|
|
||||||
[node name="StepAudio" type="AudioStreamPlayer3D" parent="."]
|
[node name="StepAudio" type="AudioStreamPlayer3D" parent="."]
|
||||||
|
|
@ -8794,9 +8806,10 @@ land_sound = NodePath("../../LandAudio")
|
||||||
script = ExtResource("19_rwwcc")
|
script = ExtResource("19_rwwcc")
|
||||||
animation_player = NodePath("../../AnimationPlayer")
|
animation_player = NodePath("../../AnimationPlayer")
|
||||||
|
|
||||||
[node name="PlayerMovement" type="Node" parent="." node_paths=PackedStringArray("player")]
|
[node name="PlayerMovement" type="Node" parent="." node_paths=PackedStringArray("player", "player_input")]
|
||||||
script = ExtResource("19_70eug")
|
script = ExtResource("19_70eug")
|
||||||
player = NodePath("..")
|
player = NodePath("..")
|
||||||
|
player_input = NodePath("../PlayerInput")
|
||||||
|
|
||||||
[node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player")]
|
[node name="WeaponSystem" type="Node" parent="." node_paths=PackedStringArray("animation_player", "camera", "player")]
|
||||||
script = ExtResource("4_qlg0r")
|
script = ExtResource("4_qlg0r")
|
||||||
|
|
@ -8841,6 +8854,10 @@ material = ExtResource("26_r2jxp")
|
||||||
player = NodePath("..")
|
player = NodePath("..")
|
||||||
blue_team_texture = ExtResource("27_j3w78")
|
blue_team_texture = ExtResource("27_j3w78")
|
||||||
|
|
||||||
|
[node name="PlayerInput" type="MultiplayerSynchronizer" parent="."]
|
||||||
|
replication_config = SubResource("SceneReplicationConfig_5amik")
|
||||||
|
script = ExtResource("37_b2eak")
|
||||||
|
|
||||||
[connection signal="died" from="." to="molikman_ingame/VisibleEnabler" method="reverse"]
|
[connection signal="died" from="." to="molikman_ingame/VisibleEnabler" method="reverse"]
|
||||||
[connection signal="died" from="." to="Camera3D" method="disable"]
|
[connection signal="died" from="." to="Camera3D" method="disable"]
|
||||||
[connection signal="died" from="." to="Camera3D/DeadSpectator" method="set_active"]
|
[connection signal="died" from="." to="Camera3D/DeadSpectator" method="set_active"]
|
||||||
|
|
@ -8848,5 +8865,4 @@ blue_team_texture = ExtResource("27_j3w78")
|
||||||
[connection signal="died" from="." to="PlayerMovement" method="disable"]
|
[connection signal="died" from="." to="PlayerMovement" method="disable"]
|
||||||
[connection signal="died" from="." to="WeaponSystem" method="disable"]
|
[connection signal="died" from="." to="WeaponSystem" method="disable"]
|
||||||
[connection signal="health_changed" from="." to="HUD/Healthbar" method="on_hp_changed"]
|
[connection signal="health_changed" from="." to="HUD/Healthbar" method="on_hp_changed"]
|
||||||
[connection signal="spawned" from="." to="TeamUpdater" method="on_spawned"]
|
|
||||||
[connection signal="ammo_updated" from="WeaponSystem" to="HUD/AmmoDisplay" method="on_ammo_updated"]
|
[connection signal="ammo_updated" from="WeaponSystem" to="HUD/AmmoDisplay" method="on_ammo_updated"]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
extends MultiplayerSynchronizer
|
extends MultiplayerSynchronizer
|
||||||
|
|
||||||
|
class_name PlayerInput
|
||||||
|
|
||||||
#region SYNC
|
#region SYNC
|
||||||
var direction: Vector2
|
@export var direction: Vector2
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
var crouching: bool = false
|
var crouching: bool = false
|
||||||
|
|
@ -24,13 +26,12 @@ signal walk_end
|
||||||
signal interact_begin
|
signal interact_begin
|
||||||
signal interact_end
|
signal interact_end
|
||||||
|
|
||||||
func _ready() -> void:
|
func _process(_delta: float) -> void:
|
||||||
set_multiplayer_authority(int(get_parent().name))
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
|
||||||
if not is_multiplayer_authority(): return
|
if not is_multiplayer_authority(): return
|
||||||
direction = Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
direction = Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||||
|
|
||||||
|
func _input(event: InputEvent) -> void:
|
||||||
|
if not is_multiplayer_authority(): return
|
||||||
if event.is_action_pressed("plr_ult"):
|
if event.is_action_pressed("plr_ult"):
|
||||||
switch_on_server.rpc_id(1,"ultimate")
|
switch_on_server.rpc_id(1,"ultimate")
|
||||||
elif event.is_action_pressed("plr_bomb"):
|
elif event.is_action_pressed("plr_bomb"):
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ func spawn_player(id: int) -> void:
|
||||||
var distance = randf_range(0,spawn_radius)
|
var distance = randf_range(0,spawn_radius)
|
||||||
var angle = randf_range(0,TAU)
|
var angle = randf_range(0,TAU)
|
||||||
var new_position = global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance
|
var new_position = global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance
|
||||||
|
inst.player_id = id
|
||||||
get_parent().add_child(inst)
|
get_parent().add_child(inst)
|
||||||
inst.global_position = new_position
|
inst.global_position = new_position
|
||||||
inst.team = team
|
inst.team = team
|
||||||
|
|
@ -7,17 +7,10 @@ extends Node
|
||||||
const ATTACK_LAYER: int = 0b10000
|
const ATTACK_LAYER: int = 0b10000
|
||||||
const DEFENCE_LAYER: int = 0b100000
|
const DEFENCE_LAYER: int = 0b100000
|
||||||
|
|
||||||
func on_spawned() -> void:
|
func _ready() -> void:
|
||||||
|
if is_multiplayer_authority() == false: return
|
||||||
var mask = (ATTACK_LAYER if (player.team == Session.TEAMS.DEFENCE != inverse) else DEFENCE_LAYER)
|
var mask = (ATTACK_LAYER if (player.team == Session.TEAMS.DEFENCE != inverse) else DEFENCE_LAYER)
|
||||||
if layer:
|
if layer:
|
||||||
get_parent().collision_layer |= mask
|
get_parent().collision_layer |= mask
|
||||||
else:
|
else:
|
||||||
get_parent().collision_mask |= mask
|
get_parent().collision_mask |= mask
|
||||||
global_update.rpc(layer,mask)
|
|
||||||
|
|
||||||
@rpc
|
|
||||||
func global_update(new_layer,mask) -> void:
|
|
||||||
if new_layer:
|
|
||||||
get_parent().collision_layer |= mask
|
|
||||||
else:
|
|
||||||
get_parent().collision_mask |= mask
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,8 @@ extends Camera3D
|
||||||
|
|
||||||
var active: bool
|
var active: bool
|
||||||
|
|
||||||
func _ready() -> void:
|
func _enter_tree() -> void:
|
||||||
if not is_multiplayer_authority():
|
set_multiplayer_authority(int(get_parent().get_parent().name))
|
||||||
return
|
|
||||||
|
|
||||||
func set_active() -> void:
|
func set_active() -> void:
|
||||||
if not is_multiplayer_authority():
|
if not is_multiplayer_authority():
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,13 @@ class_name Player
|
||||||
|
|
||||||
@export var team: Session.TEAMS
|
@export var team: Session.TEAMS
|
||||||
@export var weapon_models: Dictionary[StringName,Node3D]
|
@export var weapon_models: Dictionary[StringName,Node3D]
|
||||||
|
@export var player_id: int = 1:
|
||||||
|
set(id):
|
||||||
|
player_id = id
|
||||||
|
$PlayerInput.set_multiplayer_authority(id)
|
||||||
|
|
||||||
var passived: bool = false
|
var passived: bool = false
|
||||||
|
|
||||||
signal spawned
|
|
||||||
signal health_changed(to: int)
|
signal health_changed(to: int)
|
||||||
signal died
|
signal died
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ extends Node
|
||||||
class_name PlayerMovement
|
class_name PlayerMovement
|
||||||
|
|
||||||
@export var player: Player
|
@export var player: Player
|
||||||
|
@export var player_input: PlayerInput
|
||||||
var disabled: bool
|
var disabled: bool
|
||||||
|
|
||||||
func disable() -> void:
|
func disable() -> void:
|
||||||
|
|
@ -15,7 +16,7 @@ func process_movement(max_speed: float,acceleration: float,deceleration: float,d
|
||||||
player.velocity.x = 0
|
player.velocity.x = 0
|
||||||
player.velocity.z = 0
|
player.velocity.z = 0
|
||||||
return
|
return
|
||||||
var input_dir := Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
var input_dir := player_input.direction
|
||||||
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
var direction := (player.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||||
if direction:
|
if direction:
|
||||||
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-max_speed*abs(direction.x),max_speed*abs(direction.x))
|
player.velocity.x = clamp(player.velocity.x + direction.x * acceleration * delta,-max_speed*abs(direction.x),max_speed*abs(direction.x))
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,5 @@ extends Node
|
||||||
@export var blue_team_texture: Texture2D
|
@export var blue_team_texture: Texture2D
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
get_tree().create_timer(1).timeout.connect(on_player_spawned)
|
|
||||||
|
|
||||||
func on_player_spawned() -> void:
|
|
||||||
if player.team == Session.TEAMS.DEFENCE:
|
if player.team == Session.TEAMS.DEFENCE:
|
||||||
material.albedo_texture = blue_team_texture
|
material.albedo_texture = blue_team_texture
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func fire() -> void:
|
||||||
machine.animation_player.play(with_morphems("shoot"))
|
machine.animation_player.play(with_morphems("shoot"))
|
||||||
|
|
||||||
if is_multiplayer_authority():
|
if is_multiplayer_authority():
|
||||||
Session.shoot(damage,shoot_distance)
|
Session.shoot(int(machine.player.name),damage,shoot_distance)
|
||||||
|
|
||||||
fire_timer.start()
|
fire_timer.start()
|
||||||
machine.player_camera.recoil(horizontal_curve.sample(bullets_shot),vertical_curve.sample(bullets_shot))
|
machine.player_camera.recoil(horizontal_curve.sample(bullets_shot),vertical_curve.sample(bullets_shot))
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ func exit() -> void:
|
||||||
|
|
||||||
func attack() -> void:
|
func attack() -> void:
|
||||||
if is_multiplayer_authority():
|
if is_multiplayer_authority():
|
||||||
Session.shoot(damage,1.5)
|
Session.shoot(int(machine.player.name),damage,1.5)
|
||||||
|
|
||||||
func on_animation_finished(animation):
|
func on_animation_finished(animation):
|
||||||
if animation == machine.animation_prefix + "attack":
|
if animation == machine.animation_prefix + "attack":
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ func exit() -> void:
|
||||||
|
|
||||||
func attack() -> void:
|
func attack() -> void:
|
||||||
if is_multiplayer_authority():
|
if is_multiplayer_authority():
|
||||||
Session.shoot(damage,1.5)
|
Session.shoot(int(machine.player.name),damage,1.5)
|
||||||
|
|
||||||
func on_animation_finished(animation):
|
func on_animation_finished(animation):
|
||||||
if animation == machine.animation_prefix + "heavy_attack":
|
if animation == machine.animation_prefix + "heavy_attack":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue