Move the real player authority to server
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
- Add rust bindings for the server player controller - Implement reconciliation loop for checking the player state - Place spawners on the test map - Add Containerfile and helm chart
This commit is contained in:
@ -22,14 +22,17 @@ var model: Node3D = null
|
||||
# -- This node is supposed to be spawned per player, and since each
|
||||
# -- player has an id, it is used for giving a node a name. So we can
|
||||
# -- use it here to tell a controlled node from the rest models
|
||||
@onready var owner_id: int = str($".".name).to_int()
|
||||
@onready var owner_id_detected: int = str($".".name).to_int()
|
||||
@export var owner_id: int = 0
|
||||
var multiplayer_id: int = 0
|
||||
|
||||
# -- Character state
|
||||
var alive: bool = true
|
||||
|
||||
func _ready() -> void:
|
||||
player_synchronizer.set_multiplayer_authority(owner_id)
|
||||
owner_id = owner_id_detected
|
||||
$PlayerInput.set_multiplayer_authority(owner_id)
|
||||
player_synchronizer.set_multiplayer_authority(1)
|
||||
multiplayer_id = multiplayer.get_unique_id()
|
||||
# -- Separate logic for player and other models that are controlled
|
||||
# -- by other players on the server
|
||||
@ -39,19 +42,19 @@ func _ready() -> void:
|
||||
if _is_current_player():
|
||||
var err := _add_first_view_model()
|
||||
if err != OK:
|
||||
print("Error occured: " + str(err))
|
||||
push_error("Error occured: " + str(err))
|
||||
err = _add_legs_to_first_view()
|
||||
if err != OK:
|
||||
print("Error occured: " + str(err))
|
||||
push_error("Error occured: " + str(err))
|
||||
var world_model := _add_world_model()
|
||||
if world_model == null:
|
||||
print("Error occured: " + "couldn't load the world model")
|
||||
push_error("Error occured: " + "couldn't load the world model")
|
||||
|
||||
_enable_camera()
|
||||
else:
|
||||
var world_model := _add_world_model()
|
||||
if world_model == null:
|
||||
print("Error occured: " + "couldn't load the world model")
|
||||
push_error("Error occured: " + "couldn't load the world model")
|
||||
_hide_camera_mount()
|
||||
|
||||
_capture_mouse()
|
||||
@ -182,10 +185,17 @@ func _unhandled_input(event: InputEvent) -> void:
|
||||
#if Input.is_action_just_pressed("reload"): $Body/UpperTorso/CameraMount/Camera.reload()
|
||||
|
||||
func _rotate_camera(sens_mod: float = 1.0) -> void:
|
||||
pass
|
||||
#if str($"..".name).to_int() == multiplayer.get_unique_id():
|
||||
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)
|
||||
|
||||
#@export var player := 1:
|
||||
#set(id):
|
||||
#player = id
|
||||
#$PlayerInput.set_multiplayer_authority(id)
|
||||
|
||||
@onready var input = $PlayerInput
|
||||
@onready var hud = $FirstPersonCameraMount/HUD
|
||||
@onready var health_indicator = $FirstPersonCameraMount/HUD/HealthIndicator
|
||||
@onready var fps_indicator = $FirstPersonCameraMount/HUD/FPS
|
||||
@ -209,16 +219,15 @@ func _physics_process(delta: float) -> void:
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("jump") and is_on_floor():
|
||||
if input.jumping and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
input.jumping = false
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
#var input_dir := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||
# -- It shouldn't be possible to change direction during the jumps
|
||||
if is_on_floor():
|
||||
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_backwards")
|
||||
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
var direction := (transform.basis * Vector3(input.input_direction.x, 0, input.input_direction.y)).normalized()
|
||||
if direction:
|
||||
gun_mount_anim.play("move")
|
||||
if first_view_legs_anim != null:
|
||||
@ -274,7 +283,6 @@ func _get_camera_collision():
|
||||
var intersection = get_world_3d().direct_space_state.intersect_ray(new_intersection)
|
||||
if not intersection.is_empty():
|
||||
var collision_point = intersection.position
|
||||
print("gotcha")
|
||||
return collision_point
|
||||
else:
|
||||
return ray_end
|
||||
@ -286,12 +294,10 @@ func _hit_scan_collision(collision_point):
|
||||
var new_intersection = PhysicsRayQueryParameters3D.create(ray_origin, ray_end)
|
||||
var bullet_collision = get_world_3d().direct_space_state.intersect_ray(new_intersection)
|
||||
if bullet_collision:
|
||||
print(bullet_collision)
|
||||
_hit_scan_damage(bullet_collision.collider)
|
||||
|
||||
func _hit_scan_damage(Collider):
|
||||
#if Collider.is_in_group("target") and Collider.has_method("take_damage"):
|
||||
print("damaged")
|
||||
|
||||
func take_damage(dam: int):
|
||||
var new_health = health - dam
|
||||
|
Reference in New Issue
Block a user