movement sync
This commit is contained in:
parent
daa83ce96d
commit
bb3a14ece7
13 changed files with 46 additions and 35 deletions
|
|
@ -1,7 +1,9 @@
|
|||
extends MultiplayerSynchronizer
|
||||
|
||||
class_name PlayerInput
|
||||
|
||||
#region SYNC
|
||||
var direction: Vector2
|
||||
@export var direction: Vector2
|
||||
#endregion
|
||||
|
||||
var crouching: bool = false
|
||||
|
|
@ -24,13 +26,12 @@ signal walk_end
|
|||
signal interact_begin
|
||||
signal interact_end
|
||||
|
||||
func _ready() -> void:
|
||||
set_multiplayer_authority(int(get_parent().name))
|
||||
func _process(_delta: float) -> void:
|
||||
if not is_multiplayer_authority(): return
|
||||
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
|
||||
direction = Input.get_vector("plr_strafe_r","plr_strafe_l", "plr_back","plr_forward")
|
||||
|
||||
if event.is_action_pressed("plr_ult"):
|
||||
switch_on_server.rpc_id(1,"ultimate")
|
||||
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 angle = randf_range(0,TAU)
|
||||
var new_position = global_position + Vector3.RIGHT.rotated(Vector3.UP,angle) * distance
|
||||
inst.player_id = id
|
||||
get_parent().add_child(inst)
|
||||
inst.global_position = new_position
|
||||
inst.team = team
|
||||
|
|
@ -7,17 +7,10 @@ extends Node
|
|||
const ATTACK_LAYER: int = 0b10000
|
||||
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)
|
||||
if layer:
|
||||
get_parent().collision_layer |= mask
|
||||
else:
|
||||
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
|
||||
|
||||
func _ready() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
func _enter_tree() -> void:
|
||||
set_multiplayer_authority(int(get_parent().get_parent().name))
|
||||
|
||||
func set_active() -> void:
|
||||
if not is_multiplayer_authority():
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@ class_name Player
|
|||
|
||||
@export var team: Session.TEAMS
|
||||
@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
|
||||
|
||||
signal spawned
|
||||
signal health_changed(to: int)
|
||||
signal died
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ extends Node
|
|||
class_name PlayerMovement
|
||||
|
||||
@export var player: Player
|
||||
@export var player_input: PlayerInput
|
||||
var disabled: bool
|
||||
|
||||
func disable() -> void:
|
||||
|
|
@ -15,7 +16,7 @@ func process_movement(max_speed: float,acceleration: float,deceleration: float,d
|
|||
player.velocity.x = 0
|
||||
player.velocity.z = 0
|
||||
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()
|
||||
if direction:
|
||||
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
|
||||
|
||||
func _ready() -> void:
|
||||
get_tree().create_timer(1).timeout.connect(on_player_spawned)
|
||||
|
||||
func on_player_spawned() -> void:
|
||||
if player.team == Session.TEAMS.DEFENCE:
|
||||
material.albedo_texture = blue_team_texture
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func fire() -> void:
|
|||
machine.animation_player.play(with_morphems("shoot"))
|
||||
|
||||
if is_multiplayer_authority():
|
||||
Session.shoot(damage,shoot_distance)
|
||||
Session.shoot(int(machine.player.name),damage,shoot_distance)
|
||||
|
||||
fire_timer.start()
|
||||
machine.player_camera.recoil(horizontal_curve.sample(bullets_shot),vertical_curve.sample(bullets_shot))
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func exit() -> void:
|
|||
|
||||
func attack() -> void:
|
||||
if is_multiplayer_authority():
|
||||
Session.shoot(damage,1.5)
|
||||
Session.shoot(int(machine.player.name),damage,1.5)
|
||||
|
||||
func on_animation_finished(animation):
|
||||
if animation == machine.animation_prefix + "attack":
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ func exit() -> void:
|
|||
|
||||
func attack() -> void:
|
||||
if is_multiplayer_authority():
|
||||
Session.shoot(damage,1.5)
|
||||
Session.shoot(int(machine.player.name),damage,1.5)
|
||||
|
||||
func on_animation_finished(animation):
|
||||
if animation == machine.animation_prefix + "heavy_attack":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue