WIP: Some updates
This commit is contained in:
12
godot/scenes/player/gun_mount.gd
Normal file
12
godot/scenes/player/gun_mount.gd
Normal file
@ -0,0 +1,12 @@
|
||||
extends Node3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
@export var follow_speed: float = 5.0
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
var target_position = global_transform.origin # Camera's world position
|
||||
global_transform.origin = lerp(global_transform.origin, target_position, follow_speed * delta)
|
5
godot/scenes/player/hud.gd
Normal file
5
godot/scenes/player/hud.gd
Normal file
@ -0,0 +1,5 @@
|
||||
extends Control
|
||||
class_name Hud
|
||||
|
||||
@onready var camera: Camera3D = $SubViewportContainer/SubViewport/Camera3D
|
||||
@onready var gun_mount: Node3D = $SubViewportContainer/SubViewport/Camera3D/GunMounta
|
@ -1,6 +1,8 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://btlkodvngm634"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://btlkodvngm634"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/player/hud.gd" id="1_1ffy2"]
|
||||
[ext_resource type="Texture2D" uid="uid://oopj5mj1vdp0" path="res://assets/crosshairs/crosshair_default.png" id="1_u13st"]
|
||||
[ext_resource type="Script" path="res://scenes/player/gun_mount.gd" id="3_qmcsd"]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_3bk8i"]
|
||||
font_size = 70
|
||||
@ -82,6 +84,7 @@ anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
script = ExtResource("1_1ffy2")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
layout_mode = 1
|
||||
@ -141,6 +144,7 @@ environment = SubResource("Environment_i2xeo")
|
||||
fov = 50.0
|
||||
|
||||
[node name="GunMount" type="Node3D" parent="SubViewportContainer/SubViewport/Camera3D"]
|
||||
script = ExtResource("3_qmcsd")
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="SubViewportContainer/SubViewport/Camera3D/GunMount"]
|
||||
libraries = {
|
||||
|
@ -21,7 +21,9 @@ var controlled_node: ServerNode = null
|
||||
@onready var shared_node: CharacterBody3D = $SharedNode
|
||||
@onready var camera_mount: Node3D = $SharedNode/CameraMount
|
||||
@onready var camera: Camera3D = $SharedNode/CameraMount/Camera3D
|
||||
var hud: Control
|
||||
var hud: Hud
|
||||
var hud_camera: Camera3D
|
||||
var gun_mount: Node3D
|
||||
const DEFAULT_WEAPON := "ak"
|
||||
var first_slot_weapon: WeaponController
|
||||
|
||||
@ -31,11 +33,15 @@ func _ready() -> void:
|
||||
shared_node.set_collision_mask_value(1, true)
|
||||
shared_node.set_collision_mask_value(2, true)
|
||||
camera.make_current()
|
||||
print(controlled_node.shared_node.global_position)
|
||||
var hud_scene: PackedScene = ResourceLoader.load("res://scenes/player/hud.tscn")
|
||||
hud = hud_scene.instantiate()
|
||||
camera.add_child(hud)
|
||||
hud_camera = hud.camera
|
||||
gun_mount = hud.gun_mount
|
||||
_load_weapon()
|
||||
for child in controlled_node.find_child("Model").find_children("*"):
|
||||
if child is MeshInstance3D:
|
||||
child.set_layer_mask_value(1, false)
|
||||
# Load the default weapon and set the current attack properties
|
||||
|
||||
func _load_weapon() -> void:
|
||||
@ -44,12 +50,14 @@ func _load_weapon() -> void:
|
||||
var scene: PackedScene = ResourceLoader.load(path)
|
||||
var node: WeaponController = scene.instantiate()
|
||||
first_slot_weapon = node
|
||||
for child in node.find_children("*"):
|
||||
if child is MeshInstance3D:
|
||||
child.set_layer_mask_value(1, false)
|
||||
#first_slot_weapon.position = Vector3(-1, -1, -1)
|
||||
hud.find_child("GunMount").add_child(first_slot_weapon)
|
||||
|
||||
|
||||
func initial_position_sync():
|
||||
print(controlled_node.shared_node.global_position)
|
||||
shared_node.global_position = controlled_node.shared_node.global_position
|
||||
shared_node.rotation = controlled_node.shared_node.rotation
|
||||
|
||||
@ -76,7 +84,7 @@ func jump():
|
||||
jumping = true
|
||||
controlled_node.jump.rpc_id(1)
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
func _physics_process(delta: float) -> void:
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
|
||||
@ -100,6 +108,8 @@ func _physics_process(delta: float) -> void:
|
||||
else:
|
||||
shared_node.velocity.x = move_toward(shared_node.velocity.x, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||||
shared_node.velocity.z = move_toward(shared_node.velocity.z, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||||
hud_camera.global_position = global_position
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
shared_node.move_and_slide()
|
||||
|
@ -31,7 +31,9 @@ func _load_weapon() -> void:
|
||||
var scene: PackedScene = ResourceLoader.load(path)
|
||||
var node: WeaponController = scene.instantiate()
|
||||
first_slot_weapon = node
|
||||
first_slot_weapon.make_invisible()
|
||||
first_slot_weapon.set_map_controller(map_controller)
|
||||
add_child(first_slot_weapon)
|
||||
|
||||
func bind_player_node() -> void:
|
||||
if multiplayer.get_unique_id() == owner_id:
|
||||
@ -44,22 +46,34 @@ func _physics_process(delta: float) -> void:
|
||||
shared_node.velocity.y = consts.DEFAULT_JUMP_VELOCITY
|
||||
#if shooting:
|
||||
jumping = false
|
||||
|
||||
var direction := (shared_node.transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
if shared_node.is_on_floor():
|
||||
if direction:
|
||||
#first_view_legs_anim.play("Run Forward")
|
||||
shared_node.velocity.x = direction.x * consts.DEFAULT_CHARACTER_SPEED
|
||||
shared_node.velocity.z = direction.z * consts.DEFAULT_CHARACTER_SPEED
|
||||
else:
|
||||
shared_node.velocity.x = move_toward(shared_node.velocity.x, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||||
shared_node.velocity.z = move_toward(shared_node.velocity.z, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||||
if multiplayer.is_server():
|
||||
var direction := (shared_node.transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
if shared_node.is_on_floor():
|
||||
if direction:
|
||||
$SharedNode/Character/Model/AnimationPlayer.play("riffle_run")
|
||||
#first_view_legs_anim.play("Run Forward")
|
||||
shared_node.velocity.x = direction.x * consts.DEFAULT_CHARACTER_SPEED
|
||||
shared_node.velocity.z = direction.z * consts.DEFAULT_CHARACTER_SPEED
|
||||
else:
|
||||
$SharedNode/Character/Model/AnimationPlayer.play("riffle_idle")
|
||||
shared_node.velocity.x = move_toward(shared_node.velocity.x, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||||
shared_node.velocity.z = move_toward(shared_node.velocity.z, 0, consts.DEFAULT_CHARACTER_SPEED)
|
||||
sync_velocity.rpc(shared_node.velocity.x, shared_node.velocity.y, shared_node.velocity.z)
|
||||
else:
|
||||
print(str(name) + str(shared_node.velocity))
|
||||
|
||||
shared_node.move_and_slide()
|
||||
|
||||
@rpc("any_peer", "call_local", "unreliable")
|
||||
func jump():
|
||||
jumping = true
|
||||
|
||||
@rpc("any_peer", "call_local", "unreliable")
|
||||
func sync_velocity(x: float, y: float, z: float) -> void:
|
||||
if not multiplayer.is_server():
|
||||
shared_node.velocity = Vector3(x, y ,z)
|
||||
|
||||
|
||||
@rpc("any_peer", "call_local", "unreliable")
|
||||
func set_input_direction(new_input_direction: Vector2):
|
||||
input_direction = new_input_direction
|
||||
@ -74,10 +88,22 @@ func set_rotation_y(y: float):
|
||||
|
||||
func _on_reconciliation_timer_timeout() -> void:
|
||||
if multiplayer.is_server():
|
||||
player_node.verify_position.rpc_id(owner_id)
|
||||
player_node.verify_rotation.rpc_id(owner_id)
|
||||
_veryfy_position_and_rotation.rpc_id(owner_id)
|
||||
$ReconciliationTimer.start()
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func _veryfy_position_and_rotation() -> void:
|
||||
player_node.verify_position()
|
||||
player_node.verify_rotation()
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func _adjust_position(x: float, y: float, z: float) -> void:
|
||||
player_node.adjust_position(x, y, z)
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func _adjust_rotation(x: float, y: float, z: float) -> void:
|
||||
player_node.adjust_rotation(x, y, z)
|
||||
|
||||
@rpc("any_peer", "call_local", "reliable")
|
||||
func send_position(x: float, y: float, z: float):
|
||||
if multiplayer.is_server():
|
||||
@ -90,22 +116,23 @@ func send_position(x: float, y: float, z: float):
|
||||
elif is_vector_a_lower_than_b(difference, Vector3(0.4, 0.4, 0.4)):
|
||||
var new_position: Vector3 = desired_position.lerp(real_position, 0.5)
|
||||
push_warning("player position is not valid, lerping")
|
||||
player_node.adjust_position.rpc_id(owner_id, new_position.x, new_position.y, new_position.z)
|
||||
_adjust_position.rpc_id(owner_id, new_position.x, new_position.y, new_position.z)
|
||||
else:
|
||||
push_warning("player position is not valid, adjusting")
|
||||
player_node.adjust_position.rpc_id(owner_id, real_position.x, real_position.y, real_position.z)
|
||||
_adjust_position.rpc_id(owner_id, real_position.x, real_position.y, real_position.z)
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func send_rotation(x: float, y: float, z: float):
|
||||
var desired_rotation: Vector3 = Vector3(x, y, z)
|
||||
if multiplayer.is_server():
|
||||
var real_rotation: Vector3 = shared_node.rotation
|
||||
var difference: Vector3 = desired_rotation - real_rotation
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.3, 0.3, 0.3)):
|
||||
shared_node.rotation = desired_rotation
|
||||
else:
|
||||
var new_rotation: Vector3 = desired_rotation.lerp(real_rotation, 0.5)
|
||||
player_node.adjust_rotation.rpc_id(owner_id, new_rotation.x, new_rotation.y, new_rotation.z)
|
||||
var desired_rotation: Vector3 = Vector3(x, y, z)
|
||||
if multiplayer.is_server():
|
||||
var real_rotation: Vector3 = shared_node.rotation
|
||||
var difference: Vector3 = desired_rotation - real_rotation
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.3, 0.3, 0.3)):
|
||||
shared_node.rotation = desired_rotation
|
||||
else:
|
||||
var new_rotation: Vector3 = desired_rotation.lerp(real_rotation, 0.5)
|
||||
_adjust_rotation.rpc_id(owner_id, new_rotation.x, new_rotation.y, new_rotation.z)
|
||||
|
||||
@rpc("any_peer", "call_local", "unreliable_ordered")
|
||||
func shoot():
|
||||
|
@ -1,15 +1,16 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://clq0b7tbincut"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://clq0b7tbincut"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/player/server_node.gd" id="1_bau14"]
|
||||
[ext_resource type="PackedScene" uid="uid://cirun2v34nfpg" path="res://scenes/player/shared_node.tscn" id="1_ybp5y"]
|
||||
[ext_resource type="PackedScene" uid="uid://ddwrs0so7swxn" path="res://scenes/characters/y-bot/character.tscn" id="3_eykxo"]
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_2dhi2"]
|
||||
properties/0/path = NodePath("SharedNode:position")
|
||||
properties/0/spawn = true
|
||||
properties/0/replication_mode = 1
|
||||
properties/0/replication_mode = 0
|
||||
properties/1/path = NodePath("SharedNode:rotation")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
properties/1/replication_mode = 0
|
||||
properties/2/path = NodePath(".:owner_id")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 1
|
||||
@ -19,6 +20,9 @@ script = ExtResource("1_bau14")
|
||||
|
||||
[node name="SharedNode" parent="." instance=ExtResource("1_ybp5y")]
|
||||
|
||||
[node name="Character" parent="SharedNode" instance=ExtResource("3_eykxo")]
|
||||
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_2dhi2")
|
||||
|
||||
|
@ -15,6 +15,7 @@ shape = SubResource("CapsuleShape3D_r38x6")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.6036, -0.127098)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="CameraMount"]
|
||||
cull_mask = 524285
|
||||
|
||||
[node name="BulletStartingPoint" type="Node3D" parent="CameraMount"]
|
||||
transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
Reference in New Issue
Block a user