This commit is contained in:
@ -24,6 +24,8 @@ func _ready() -> void:
|
||||
$Timer.start()
|
||||
if owner_id != multiplayer.get_unique_id():
|
||||
client_node.queue_free()
|
||||
else:
|
||||
client_node._add_legs_to_first_view()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
@ -67,10 +69,11 @@ func send_position(x: float, y: float, z: float):
|
||||
if multiplayer.is_server():
|
||||
var real_position: Vector3 = server_node.global_position
|
||||
var difference: Vector3 = desired_position - real_position
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.1, 0.1, 0.1)):
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.3, 0.3, 0.3)):
|
||||
server_node.global_position = desired_position
|
||||
else:
|
||||
adjust_position.rpc_id(owner_id, real_position.x, real_position.y, real_position.z)
|
||||
var new_position: Vector3 = desired_position.lerp(real_position, 0.5)
|
||||
adjust_position.rpc_id(owner_id, new_position.x, new_position.y, new_position.z)
|
||||
|
||||
@rpc("authority", "call_local")
|
||||
func adjust_position(x: float, y: float, z: float):
|
||||
@ -91,10 +94,11 @@ func send_rotation(x: float, y: float, z: float):
|
||||
if multiplayer.is_server():
|
||||
var real_rotation: Vector3 = server_node.rotation
|
||||
var difference: Vector3 = desired_rotation - real_rotation
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.1, 0.1, 0.1)):
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.3, 0.3, 0.3)):
|
||||
server_node.rotation = desired_rotation
|
||||
else:
|
||||
adjust_rotation.rpc_id(owner_id, real_rotation.x, real_rotation.y, real_rotation.z)
|
||||
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")
|
||||
func adjust_rotation(x: float, y: float, z: float):
|
||||
|
@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://bmm3brgvr4d86"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://bmm3brgvr4d86"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/player/player_input_controller.gd" id="1_m6tul"]
|
||||
[ext_resource type="Script" path="res://scenes/player/placeholder.gd" id="1_ts455"]
|
||||
[ext_resource type="Texture2D" uid="uid://oopj5mj1vdp0" path="res://assets/crosshairs/crosshair_default.png" id="3_8ulsx"]
|
||||
[ext_resource type="Script" path="res://scenes/player/server_player_controller.gd" id="3_f1bhn"]
|
||||
[ext_resource type="PackedScene" uid="uid://dtvo21mk1webd" path="res://scenes/weapon/guns/ak/with_hands.tscn" id="3_xxv4y"]
|
||||
[ext_resource type="PackedScene" uid="uid://1txob6jskn5s" path="res://scenes/characters/blue/dummy.tscn" id="6_e3cnh"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_taqso"]
|
||||
radius = 0.4
|
||||
@ -35,7 +36,7 @@ tracks/0/keys = {
|
||||
[sub_resource type="Animation" id="Animation_mkk0p"]
|
||||
resource_name = "move"
|
||||
length = 0.5
|
||||
loop_mode = 1
|
||||
loop_mode = 2
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
@ -46,7 +47,7 @@ tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.125, 0.25, 0.375, 0.5),
|
||||
"transitions": PackedFloat32Array(1, 2, 1, 2, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0, 0, 0), Vector3(0.001, 0.001, -0.001), Vector3(0, 0, 0), Vector3(-0.001, 0.001, -0.001), Vector3(0, 0, 0)]
|
||||
"values": [Vector3(0, 0, 0), Vector3(-0.1, 0.1, -0.1), Vector3(0, 0, 0), Vector3(-0.1, 0.1, -0.1), Vector3(0, 0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_ah507"]
|
||||
@ -100,7 +101,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.786919, 0)
|
||||
shape = SubResource("CapsuleShape3D_taqso")
|
||||
|
||||
[node name="CameraMount" type="Node3D" parent="PlayerControlledNode"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.29568, -0.128668)
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.29568, -0.340905)
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="PlayerControlledNode/CameraMount"]
|
||||
cull_mask = 524287
|
||||
@ -171,8 +172,16 @@ render_target_update_mode = 4
|
||||
cull_mask = 524288
|
||||
fov = 40.0
|
||||
|
||||
[node name="WithHands" parent="PlayerControlledNode/CameraMount/Camera3D/HUD/SubViewportContainer/SubViewport/Camera3D" instance=ExtResource("3_xxv4y")]
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0.423577, -0.565285, -1.76074)
|
||||
[node name="GunMount" type="Node3D" parent="PlayerControlledNode/CameraMount/Camera3D/HUD/SubViewportContainer/SubViewport/Camera3D"]
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="PlayerControlledNode/CameraMount/Camera3D/HUD/SubViewportContainer/SubViewport/Camera3D/GunMount"]
|
||||
active = false
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_u1b6p")
|
||||
}
|
||||
|
||||
[node name="WithHands" parent="PlayerControlledNode/CameraMount/Camera3D/HUD/SubViewportContainer/SubViewport/Camera3D/GunMount" instance=ExtResource("3_xxv4y")]
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0.51335, -0.655058, -1.67097)
|
||||
visible = false
|
||||
|
||||
[node name="BulletStartingPoint" type="Node3D" parent="PlayerControlledNode/CameraMount"]
|
||||
@ -183,14 +192,6 @@ target_position = Vector3(0, 0, 1000)
|
||||
hit_from_inside = true
|
||||
collide_with_areas = true
|
||||
|
||||
[node name="GunMount" type="Node3D" parent="PlayerControlledNode/CameraMount"]
|
||||
visible = false
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="PlayerControlledNode/CameraMount/GunMount"]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_u1b6p")
|
||||
}
|
||||
|
||||
[node name="Node3D" type="Node3D" parent="PlayerControlledNode"]
|
||||
|
||||
[node name="ServerControlledNode" type="CharacterBody3D" parent="."]
|
||||
@ -201,6 +202,9 @@ script = ExtResource("3_f1bhn")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.786919, 0)
|
||||
shape = SubResource("CapsuleShape3D_taqso")
|
||||
|
||||
[node name="Dummy" parent="ServerControlledNode" instance=ExtResource("6_e3cnh")]
|
||||
visible = false
|
||||
|
||||
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."]
|
||||
replication_config = SubResource("SceneReplicationConfig_7vlrn")
|
||||
|
||||
|
@ -18,8 +18,8 @@ const JUMP_VELOCITY = 4.5
|
||||
|
||||
#func _ready() -> void:
|
||||
var current_gun: String = "ak"
|
||||
@onready var gun_mount: Node3D = $CameraMount/GunMount
|
||||
@onready var gun_mount_anim: AnimationPlayer = $CameraMount/GunMount/AnimationPlayer
|
||||
@onready var gun_mount: Node3D = $CameraMount/Camera3D/HUD/SubViewportContainer/SubViewport/Camera3D/GunMount
|
||||
@onready var gun_mount_anim: AnimationPlayer = $CameraMount/Camera3D/HUD/SubViewportContainer/SubViewport/Camera3D/GunMount/AnimationPlayer
|
||||
var gun_with_hands: Node3D = null
|
||||
@onready var bullet_starting_point: Node3D = $CameraMount/BulletStartingPoint
|
||||
@onready var aim_ray: RayCast3D = $CameraMount/BulletStartingPoint/AimRay
|
||||
@ -42,7 +42,7 @@ func _ready() -> void:
|
||||
current_weapon_cooldown_interwal = node.cooldown
|
||||
current_weapon_damage = node.damage
|
||||
gun_with_hands = node
|
||||
gun_camera.add_child(node)
|
||||
gun_mount.add_child(node)
|
||||
|
||||
func _input(event):
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
@ -61,12 +61,29 @@ func _process(delta: float) -> void:
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
if !paused:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
server_node.set_input_direction.rpc_id(1, input_direction)
|
||||
input_direction = Input.get_vector("move_left", "move_right", "move_forward", "move_backwards")
|
||||
server_node.set_input_direction.rpc_id(1, input_direction)
|
||||
if Input.is_action_just_pressed("jump"):
|
||||
server_node.jump.rpc_id(1)
|
||||
jump.rpc_id(1)
|
||||
if Input.is_action_pressed("shot"): _shoot()
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
if is_on_floor() && jumping:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jumping = false
|
||||
var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
if is_on_floor():
|
||||
if direction:
|
||||
first_view_legs_anim.play("Run Forward")
|
||||
gun_mount_anim.play("move")
|
||||
velocity.x = direction.x * placeholder.character_speed
|
||||
velocity.z = direction.z * placeholder.character_speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, placeholder.character_speed)
|
||||
velocity.z = move_toward(velocity.z, 0, placeholder.character_speed)
|
||||
move_and_slide()
|
||||
|
||||
|
||||
var cant_shoot: bool = false
|
||||
func _shoot():
|
||||
@ -75,22 +92,42 @@ func _shoot():
|
||||
cant_shoot = true
|
||||
await get_tree().create_timer(current_weapon_cooldown_interwal).timeout
|
||||
cant_shoot = false
|
||||
func _physics_process(delta: float) -> void:
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
if is_on_floor() && jumping:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jumping = false
|
||||
if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
if is_on_floor():
|
||||
if direction:
|
||||
velocity.x = direction.x * placeholder.character_speed
|
||||
velocity.z = direction.z * placeholder.character_speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, placeholder.character_speed)
|
||||
velocity.z = move_toward(velocity.z, 0, placeholder.character_speed)
|
||||
move_and_slide()
|
||||
|
||||
#func _physics_process(delta: float) -> void:
|
||||
#if multiplayer.get_unique_id() == get_multiplayer_authority():
|
||||
#if not is_on_floor():
|
||||
#velocity += get_gravity() * delta
|
||||
#if is_on_floor() && jumping:
|
||||
#velocity.y = JUMP_VELOCITY
|
||||
#jumping = false
|
||||
#var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
#if is_on_floor():
|
||||
#if direction:
|
||||
#velocity.x = direction.x * placeholder.character_speed
|
||||
#velocity.z = direction.z * placeholder.character_speed
|
||||
#else:
|
||||
#velocity.x = move_toward(velocity.x, 0, placeholder.character_speed)
|
||||
#velocity.z = move_toward(velocity.z, 0, placeholder.character_speed)
|
||||
#move_and_slide()
|
||||
var first_view_legs_anim: AnimationPlayer = null
|
||||
func _add_legs_to_first_view() -> Error :
|
||||
# -- TODO: It should not be hardcoded
|
||||
var path := "res://scenes/characters/blue/dummy.tscn"
|
||||
if not ResourceLoader.exists(path):
|
||||
return ERR_DOES_NOT_EXIST
|
||||
var scene: PackedScene = ResourceLoader.load(path)
|
||||
if not scene.can_instantiate():
|
||||
return ERR_CANT_OPEN
|
||||
var node: Node3D = scene.instantiate()
|
||||
var skeleton: Skeleton3D = node.find_child("Skeleton3D")
|
||||
var bone := skeleton.find_bone("mixamorig_Spine")
|
||||
if bone != -1:
|
||||
skeleton.set_bone_pose_scale(bone, Vector3(0, 0, 0))
|
||||
add_child(node)
|
||||
var animation_node: AnimationPlayer = node.find_child("AnimationPlayer")
|
||||
if animation_node != null:
|
||||
first_view_legs_anim = animation_node
|
||||
return OK
|
||||
|
||||
var camera_sens: float = 0.002
|
||||
|
||||
|
@ -32,13 +32,13 @@ func _physics_process(delta: float) -> void:
|
||||
if is_on_floor() && jumping:
|
||||
velocity.y = JUMP_VELOCITY
|
||||
jumping = false
|
||||
|
||||
var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
#if is_on_floor():
|
||||
if direction:
|
||||
velocity.x = direction.x * placeholder.character_speed
|
||||
velocity.z = direction.z * placeholder.character_speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, placeholder.character_speed)
|
||||
velocity.z = move_toward(velocity.z, 0, placeholder.character_speed)
|
||||
if is_on_floor():
|
||||
var direction := (transform.basis * Vector3(input_direction.x, 0, input_direction.y)).normalized()
|
||||
#if is_on_floor():
|
||||
if direction:
|
||||
velocity.x = direction.x * placeholder.character_speed
|
||||
velocity.z = direction.z * placeholder.character_speed
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, placeholder.character_speed)
|
||||
velocity.z = move_toward(velocity.z, 0, placeholder.character_speed)
|
||||
move_and_slide()
|
||||
|
Reference in New Issue
Block a user